Jump to content

proper way to trigger something once per day?


davidlallen

Recommended Posts

I have a creature, and I want to check a certain condition once per day. I have found the technique of using int(GameDaysPassed) which is used, for example, in Veronica's quest when you are asked to return one day later when Doctor Schiller is back. So I add a script to the creature:

scn DWRTestTronScript

short iLastDay
short iCurrentDay

begin onactivate player
set iLastDay to GameDaysPassed
if getdead == 1
	resurrect 1
endif
end

begin GameMode
; Just after midnight, mysteriously dies
set iCurrentDay to GameDaysPassed
if iLastDay != iCurrentDay
	set iLastDay to iCurrentDay
	kill
endif
end

 

The GameMode triggers as soon as I start the game to kill the creature. I can activate it and it resurrects. This sets iLastDay to the integer value of GameDaysPassed. As far as I understand the gamemode clause triggers every frame. So then I wait till after midnight. Now the integer value of GameDaysPassed should be different than the stored value, and the creature should die again. Well, it doesn't die.

 

Is there a better way to check something once per day? It bothers me a little that this will run every frame; there should be a more efficient timer. But even this inefficient way does not seem to work.

Link to comment
Share on other sites

It looks like it should work, but maybe something like:

short iNextDay

begin onactivate player
set iNextDay to GameDaysPassed + 1
if getdead
	resurrect 1
endif
end

begin GameMode
if getdead
elseif GameDaysPassed >= iNextDay
	kill
endif
end

Edited by Ez0n3
Link to comment
Share on other sites

After further testing, both your variant and my variant appear to work, by a different definition of "work". They do not trigger the kill at midnight, but rather 24 hours after the resurrect. I am not sure why this should be. Actually, I seem to recall the Veronica delay event I mentioned worked this way. After receiving the message to come back "tomorrow", I came back at midnight but it was not enough. I needed to wait 24 hours.

 

If I understand the trick of converting from float to int correctly, it should trigger at midnight; there should be no way for the script to remember what hour of the day it was triggered. But anyway, the current function is close enough to what I want. Your version is more efficient due to the "if getdead elseif" cutoff. Thanks for your help.

Edited by davidlallen
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...