Open XertroV opened 1 month ago
Assuming this is for something like MLFeed which other plugins depend on, couldn't you do something like this?
Foo@ g_someHandle;
void Main()
{
while (true) {
if (g_someHandle !is null) {
g_someHandle = null;
}
yield();
}
}
Foo@ GetSomeHandle()
{
if (g_someHandle is null) {
@g_someHandle = ResolveSomeHandle();
}
return g_someHandle;
}
Or am I misunderstanding the problem?
I think you're misunderstanding a bit.
ResolveSomeHandle
is expensive to do ad-hoc (like looking up a player or vehicle -- O(n)
)ResolveSomeHandle
, I set CSmPlayer@ player
on some object early that frame because I'm already looping through all the players, so it's basically freeDoes that make more sense?
Problem: there are a few cases where I'd like to structure something like this:
The goal is to store references to nods but only while it's safe. This prevents looking up the nods each time I want to access them, but also ensures they're null during the times they might be destroyed.
Not sure if AfterMain is the best way to go, but seems reasonable.
Particularly: from what I understand, dependents will always run after their dependencies. So for MLFeed, for example, there's no way to safely expose references. Though maybe BeforeScripts or something works well enough?