Jump to content

Script Blocks and Continue()


Salk

Recommended Posts

Another question.

 

If I have this in my script:

IF 
   GlobalTimerExpired("Mourn","GLOBAL")
THEN
   RESPONSE #100
     Action1
END

IF
  Condition1
THEN
  RESPONSE #100
    SetGlobalTimer("Mourn","GLOBAL", 21600)
END

Is it so that the first condition is always true and starts Action1 until Condition1 is satisfied in which case the first block will be true again only after 3 days of in-game time? Do I perhaps need a Continue() somewhere?

 

Thanks!

Link to comment

Another question.

 

If I have this in my script:

IF 
   GlobalTimerExpired("Mourn","GLOBAL")
THEN
   RESPONSE #100
     Action1
END

IF
  Condition1
THEN
  RESPONSE #100
    SetGlobalTimer("Mourn","GLOBAL", 21600)
END

Is it so that the first condition is always true and starts Action1 until Condition1 is satisfied in ..

No, if the first condition is true(GlobalTimerExpired("Mourn","GLOBAL")), the condition1 is never even read unless you put CONTINUE after the Action1. ...

Link to comment

In a script cycle, the blocks in a script are evaluated from the top of the file to the bottom and the first one with true triggers is executed. Then, the script cycle usually ends. In the next cycle, the script will be evaluated again, starting back at the top.

 

What you need to keep in mind is that as long as a block's triggers remain true, that block has the potential to execute every cycle. This means that the same actions will be repeated and blocks lower down will not be evaluated, which is probably not what you want. Adding a Continue() prevents the script cycle from ending, which allows lower blocks to be evaluated, but it does nothing to solve the problem of your block repeatedly executing.

 

To deal with this, you can add additional triggers to a block, to ensure it stops being true after it has performed its function.

 

I'm not sure I understand your specific example, but here is a way you can make a script that causes something to happen 3 days later.

IF
  <StartTimerConditions>
  Global("StartedMournTimer", "GLOBAL", 0)
THEN
  RESPONSE #100
    SetGlobalTimer("Mourn","GLOBAL", 21600)
    SetGlobal("StartedMournTimer", "GLOBAL", 1)
END

IF 
  GlobalTimerExpired("Mourn","GLOBAL")
  Global("PerformedMournActions", "GLOBAL", 0)
THEN
  RESPONSE #100
    <MournActions>
    SetGlobal("PerformedMournActions", "GLOBAL", 1)
END

Each of these blocks now executes only once. I reordered them for clarity, but it won't affect the behaviour now that they are guaranteed not to repeat.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...