openplanet-nl / issues

Issue tracker for Openplanet.
10 stars 0 forks source link

add `AfterMain` run context or similar #488

Open XertroV opened 1 month ago

XertroV commented 1 month ago

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?

codecat commented 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?

XertroV commented 1 month ago

I think you're misunderstanding a bit.

Does that make more sense?