Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a proper scripting loop
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#1
a proper scripting loop

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.
09-22-2010, 05:42 PM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#2
RE: a proper scripting loop

You do it by making a timer that calls itself.

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

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

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

    AddTimer("myloop", 0.1f, "TimerLoop");
}
09-22-2010, 06:09 PM
Website Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#3
RE: a proper scripting loop

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.
(This post was last modified: 09-22-2010, 06:33 PM by gosseyn.)
09-22-2010, 06:19 PM
Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#4
RE: a proper scripting loop

Bump,

can you help about my global variable problem, thanks.
09-23-2010, 02:02 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#5
RE: a proper scripting loop

You have to use SetLocarVarInt("NameOfVar", Value);
Post the part in which you have a problem.

09-23-2010, 02:47 PM
Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#6
RE: a proper scripting loop

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.
09-23-2010, 02:57 PM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#7
RE: a proper scripting loop

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.
(This post was last modified: 09-23-2010, 02:59 PM by jens.)
09-23-2010, 02:58 PM
Website Find




Users browsing this thread: 2 Guest(s)