Jump to content

Timer Script / Delay


Xynion

Recommended Posts

Hey guys,

 

I try to figure out how I can write the script for a timer. I want it to get activated (start at 0), count to 1, do something, count to 2, do something ... , count to 5, end. But I do not know at all how to write it. As I tried to be guided by the Autoclose-Door script I got to know that the float-command would be necessary just like if-commands with <1 and so on, but how does it actually work? I didn't find a tutorial or thread or something, and I do not understand how I can delay an action caused by a trigger (or to set multiple actions in a short frequency) (GECK-Wiki neither).

 

Does anybody know what I need for such a script?

Link to comment
Share on other sites

I want to enable one object, play a soundfile and change the Imod for the half of a secon, wait a second and repeat these steps (with another object, but I think that should be only a matter of reference), and again. Kind of Special wishes.
Link to comment
Share on other sites

That's still a little vague.

Anyway, for the timer part, try using this code, as a skeleton:

short	iState
float	fTimer

begin GameMode

	if iState
		if (fTimer >= 5) && (iState == 3)
			(Do something)
			set fTimer to 0
			set iState to 0
		elseif (fTimer >= 2) && (iState == 2)
			(Do something)
			set iState to 3
		elseif (fTimer >= 1) && (iState == 1)
			(Do something)
			set iState to 2
		endif
		set fTimer to fTimer + GetSecondsPassed
	endif

end

 

You initiate the sequence by setting iState to 1 (from whatever it is that is supposed to trigger it). The timer will then start running, performing actions after one second has passed, then after two seconds, and finally after five seconds (then it will reset).

Link to comment
Share on other sites

Thank you, that's very useful! Must I write a ""set iStage to 1""-line to start it or is the skeleton up to here sufficient? I don't have time to test it today I think, but I'll post again as soon as I can if it works as it's supposed to work.

Another question (just out of curiousity), why is the timer upside down? I'm talking about ""fTimer >= 5"" and so on. Is the order unimportant (because of ""elseif"" I presume)?

 

short DoOnce

short    iState
float    fTimer

begin OnTrigger

if iState
        if (fTimer >= 5) && (iState == 3) && DoOnce == 0

            (Do something)
            set fTimer to 0
            set iState to 0
        elseif (fTimer >= 2) && (iState == 2)
            (Do something)
            set iState to 3
        elseif (fTimer >= 1) && (iState == 1)
            (Do something)
            set iState to 2
        endif
        set fTimer to fTimer + GetSecondsPassed

        set DoOnce to 1
    endif

End

 

EdIt: Changed the purpose a bit, but the skeleton is the same. Alas it won't save... I couldn't find a mistake, but I hardly understand the whole script.

 

scn ZModLibrarySCRIPT

short DoOnce

short iState
float fTimer

begin OnTrigger

	if iState
		if (fTimer >= 5) && (iState == 3) && DoOnce == 0
			XMarker1.placeatme ZModLightExplosion
			set fTimer to 0
			set iState to 0
		elseif (fTimer >= 2) && (iState == 2)
			XMarker2.placeatme ZModLightExplosion
			set iState to 3
		elseif (fTimer >= 1) && (iState == 1)
			XMarker3.placeatme ZModLightExplosion
			set iState to 2
		endif
		set fTimer to fTimer + GetSecondsPassed
		set DoOnce to 1
	endif
End

 

Edit2: Interesting, I spelled the scriptname wrong. Now it saves. Will test it soon. Thanks up to here. :)

Edited by Xynion
Link to comment
Share on other sites

why is the timer upside down?

In this case, the order is not important. It's just how I built it.

 

Now that I see you intend to use a trigger activator, the skeleton script should look something like this:

short	iState
float	fTimer

begin OnTriggerEnter player

	set fTimer to 0
	set iState to 1

end

begin GameMode

	if iState
		if (fTimer >= 5) && (iState == 3)
			(Do something)
			set iState to 0

			; Optional:
			Disable
			MarkForDelete

		elseif (fTimer >= 2) && (iState == 2)
			(Do something)
			set iState to 3
		elseif (fTimer >= 1) && (iState == 1)
			(Do something)
			set iState to 2
		endif
		set fTimer to fTimer + GetSecondsPassed
	endif

end

A few notes:

1. I replaced OnTrigger with OnTriggerEnter. The former will run every frame, as long as there's an actor standing inside the trigger; the later will run once, only when an actor steps into the trigger. Notice that I also added 'player' afterwards. This will ensure it can only be triggered by the player. You can erase it if you intend ANY actor to be able to trigger it.

2. About the two lined I marked as optional: If this is to be a one time event - leave them. Otherwise, if you intend it to re-play itself every time someone triggers it - erase them.

Link to comment
Share on other sites

I see, witht the MarkForDelete you avoided using Short DoOnce. To this point - and so far I understand the script - it should do! The other one didn't worked out, I'll compare it with your new one tomorrow to find the mistake. I'll tell you when the new script worked. :) Thank you, I'm really glad that the people in this forum are so kind and helpful. Guess it wasn't a matter of one minute to write this script. Thanks!

Link to comment
Share on other sites

@Xynion - I think you need this link to a set of tutorials. One is for setting up a staged timer and the other is a beginning scripting tutorial for the Geck. Also, if you haven't got the wiki bookmarked you should have that too. It's invaluable for info on functions and blocktypes when scripting (at least until you begin to memorize them).

Link to comment
Share on other sites

@IlamaRCA

I actually worked a lot with the wiki to get basic knowledge and up to now it helped me a lot (skipping trough the Functions-page is very interesting). I knew the Scripting for Beginners-tutorial, but I've read it in the wiki, so the others tutorials were missing; thus thanks for the link! The tutorial on staged timers (now I even understand how his and jazzisparis script works) is also very helpful.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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