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


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

Posts: 63
Joined: Sep 2010
Reputation: 1
Post: #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 all posts by this user Quote this message in a reply
jens Offline
Frictional Games

Posts: 4,095
Joined: Apr 2006
Reputation: 202
Post: #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
Visit this user's website Find all posts by this user Quote this message in a reply
gosseyn Offline
Member

Posts: 63
Joined: Sep 2010
Reputation: 1
Post: #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 all posts by this user Quote this message in a reply
gosseyn Offline
Member

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

Bump,

can you help about my global variable problem, thanks.
09-23-2010 02:02 PM
Find all posts by this user Quote this message in a reply
Pandemoneus Offline
Senior Member

Posts: 328
Joined: Sep 2010
Reputation: 0
Post: #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 all posts by this user Quote this message in a reply
gosseyn Offline
Member

Posts: 63
Joined: Sep 2010
Reputation: 1
Post: #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 all posts by this user Quote this message in a reply
jens Offline
Frictional Games

Posts: 4,095
Joined: Apr 2006
Reputation: 202
Post: #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
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)