lorenzoulm Posted July 11, 2013 Share Posted July 11, 2013 I need to run an action in a script every second, for 90 seconds. I tried creating a timer, but it didnt work like i would.PS: I need a script, NOT an effect Link to comment Share on other sites More sharing options...
luthienanarion Posted July 12, 2013 Share Posted July 12, 2013 The easiest way to run a script for a predetermined amount of time is to call an effect that lasts for that duration. If creating a timer didn't work, make sure that the variable you are setting with GetSecondsPassed is a float and not a short. scn ninetysecondsES float timer begin scripteffectstart set timer to 0 end ; scripteffectstart begin scripteffectupdate if(timer > 1) set timer to 0 ; do something extraordinary, as long as it doesn't take longer than a second to do else set timer to getsecondspassed endif end ; scripteffectupdate begin scripteffectfinish ; do whatever at the end of the effect end ; scripteffectfinish If you simply MUST use a different script type, you could add a token to the player's inventory with an object script. scn ninetysecondsOS float timer short count begin onadd set timer to 0 set count to 0 end ; onadd begin gamemode if(count == 90) removeme else if(timer > 1) set timer to 0 set count to count + 1 ; do something extraordinary, as long as it doesn't take longer than a second to do else set timer to getsecondspassed endif end ; gamemode Link to comment Share on other sites More sharing options...
pkleiss Posted July 12, 2013 Share Posted July 12, 2013 (edited) You need some block to start your timer. In my example, I am using an OnLoad block which runs as soon as the object the script is on loads in the cell the first time. You can use other initializing blocks like OnActivate for containers, or even a script variable. SCN MyTimer Float Timer Short Retry Begin OnLoad Set Timer to 1 Set Retry to 90 End Begin GameMode If Retry If (Timer<=0) ;Do Something Set Timer to 1 Set Retry to Retry - 1 Else Set Timer to Timer - GetSecondsPassed Endif Endif EndThis example will Do Something once a second until the number of Retry reaches zero, or 90 times.The game Mode block won't run until Retry is positive and will stop when it's 0.Also, in this case, a full second will elapse before the first time Something is done. If you want the Something to occur right away, just remove the Set Timer to 1 command in the OnLoad block. EDIT: I see I was Guzumped by luth while I was writing this post...) Edited July 12, 2013 by pkleiss Link to comment Share on other sites More sharing options...
rickerhk Posted July 12, 2013 Share Posted July 12, 2013 scn MyEventTimerScript float fEventTimer float fsecondTimer short iStartAction ;Object script (or fast quest script). iStartAction can be set to 1 by another script (trigger, quest stage, dialog) BEGIN GameMode if fEventTimer >= 90 || iStartAction == 0 return endif if fsecondTimer > 0 set fsecondTimer to fsecondTimer - GetSecondsPassed else if iStartAction == 1 ; Do action here set fsecondTimer to 1 set fEventTimer to fEventTimer + GetSecondsPassed endif endif END Lol - I was double ninja'd :P Link to comment Share on other sites More sharing options...
lorenzoulm Posted July 12, 2013 Author Share Posted July 12, 2013 Thank you all. Now I only have to first understand all logic :biggrin: because even if I have some experience (not an expert) with scripting my ability with timers is very small. Link to comment Share on other sites More sharing options...
Recommended Posts