Jump to content


Photo

Alternative to OnCreation in BGn


  • Please log in to reply
No replies to this topic

#1 nullset

nullset
  • Member
  • 18 posts

Posted 16 January 2016 - 12:16 AM

I have read about modders having to insert an OnCreation script in every area in order to recover a state that is not persisted across save games. This always seemed like overkill to me. What I was looking for was a way to determine when a non-persisted state had gone bye-bye. The following code demonstrates just that:


IF
!TimerExpired(1)
THEN
  RESPONSE #100
    StartTimer(1,1)
    SetToken("RJPLAY0",@1)
END
 

!TimerExpired returns true only when the local timer has never been set because the StartTimer sets the local timer to expire virtually immediately. Since local timers are not persisted, the block will only trigger when the timer has never been set, which should only occur at start of game, on save game load, and (probably) on transition to ToB. From the code, you can see that I am using it to regenerate a SetToken which also is not persisted but is untestable.