use local object list in script that is activated after X seconds

Mmaarten
01 Apr 2020, 00:23

I want to create a function in the text (non book) quest that locks all exits that are currently unlocked and unlock only those again after a few seconds. This is because I do not want players moving rooms during conversations with characters.
I tried the following but because changedExits is a local variable that dies when the script dies, it cannot compile the script that is called after 3 seconds.

it is an objectlist so I cannot store it in an attribute. Any suggestions?

foreach (exit, AllExits()) {
  if (exit.locked = false) {
    LockExit (exit)
    list add (changedExits, exit)
  }
  SetTimeout (3) {
    foreach (exit, changedExits) {
      UnlockExit (exit)
    }
  }
}```

mrangel
01 Apr 2020, 00:40

it is an objectlist so I cannot store it in an attribute

Why not?

Also, the code you posted sets up a separate timer for every exit in the game, which will all unlock the same list of exits.
What you want is probably something like:

game.changedExits = NewObjectList()
foreach (exit, AllExits()) {
  if (not exit.locked) {
    LockExit (exit)
    list add (game.changedExits, exit)
  }
}
SetTimeout (3) {
  foreach (exit, game.changedExits) {
    UnlockExit (exit)
  }
}

Alternatively, if you don't want to store the list in an attribute for some reason, you could use a boolean attribute of the exit itself. Like this:

foreach (exit, AllExits()) {
  exit.reallyLocked = exit.locked
  exit.locked = true
}
SetTimeout (3) {
  foreach (exit, AllExits()) {
    exit.locked = exit.reallyLocked
  }
}

Both of these scripts will have issues if you run them again before the timer expires; if you need to work around that, then you'd do:

foreach (exit, AllExits()) {
  if (not HasBoolean (exit, "reallyLocked")) {
    exit.reallyLocked = exit.locked
  }
  exit.locked = true
}
SetTimeout (3) {
  foreach (exit, AllExits()) {
    exit.locked = exit.reallyLocked
    exit.reallyLocked = false
  }
}

Mmaarten
01 Apr 2020, 00:45

Thanks for the reply!

The timer/exit was indeed an error of } placement. I fixed this in the meantime already.
However, when I make an attribute with the game as parent, I can only pick "string list" and not object list. can this be bypassed with code then?

The system should also be able to run multiple times but never parallel. (all exits will be unlocked before locking again)


mrangel
01 Apr 2020, 10:21

However, when I make an attribute with the game as parent, I can only pick "string list" and not object list. can this be bypassed with code then?

I assume that's a limitation of the GUI. If you paste the code I gave into code view, it should work without problems.

The system should also be able to run multiple times but never parallel. (all exits will be unlocked before locking again)

Any of the versions I posted should work neatly in that case.