Frictional Games Forum (read-only)

Full Version: a proper scripting loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!, it's me and my loop again!

So, i really need to know how to properly script a loop, a loop that waits for player inputs. For example, let's say i want to add impulse to an object from the moment the player collides with area1 until the moment he collides with area2, how would i do that ? Or, better, how would i do if i want the loop to be effective at map start ?

I didn't came here without first trying myself with the knowledge i have, but i must admit i made the game crash each time i tried.

I don't need to know about while or do, or for, but i want to know where to place things. Where to place the loop? Inside a function i make or inside OnEnter or Onstart? I tried both, with no success. I know i need a break condition, and i have one, but still the game crashes.

So, please help me.
You do it by making a timer that calls itself.

So in the enter of an area to start the loop you have
Code:
AddTimer("myloop", 0.1f, "TimerLoop");

Then in the area to end the loop you have
Code:
RemoveTimer("myloop");

And the timer function itself should be
Code:
void TimerLoop(string &in asTimer)
{
    AddPropImpulse("BouncingObject", 0, 1, 0, "World");

    AddTimer("myloop", 0.1f, "TimerLoop");
}
My oh my, why i didn't think of that? A timer calling himself for ever !!! Nice Jens, Thank you !
And one last question while i am at it : how do i set a variable which will be available in the entire script within all functions? Can i just declare it inside OnEnter or OnStart the normal way, or do i have to use SetLocalVarInt. Because i used that function (with GetLocalVarInt), but it seems i am doing something wrong. Thank you again.
Bump,

can you help about my global variable problem, thanks.
You have to use SetLocarVarInt("NameOfVar", Value);
Post the part in which you have a problem.
well, i erased the testing i was doing about global script variable, so i have nothing to show, but roughly, i want to know where i have to declare the variable. I looked on your map.hps when i was testing Pandemoneus, and i think i did the exact same thing. You declared SetLocalVarInt inside OnStart, and then you variable is available through the entire script, and you call it with GetLocalVarInt. But i don't know what was wrong with my script.

So, can i declare everywhere, or only inside OnStart?
Thank you.
You can use Set or Add in OnStart/OnEnter or in any function and it will be accessible in the whole script after that.

So you don't have to actually declare variables, just create one with Set or Add when you need it and then access it with Get where you need to do so.