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
Help with "advanced widget script"
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#2
RE: Help with "advanced widget script"

for(int s=1;s<11;s++) AddTimer("step"+s, 0.8 * s, "CreateFootstep");


The loop there takes the following form:
for ( <1> ; <2> ; <3>)  {<4> }

<1> : Done at the very start of the loop. Usually we declare a variable.
<2> : Boolean (True/False) value deciding if we should exit the loop or not yet.
<3> : Action performed at the end of each iteration of the loop.
<4> : The actual code that is performed each iteration. (note that if only 1 thing is done you don't need the {}'s).

In this case, we define an integer variable called "s" at the start of the loop. "s" is initialised to 1, and will increment by 1 (s++) whilst "s < 11". This means AddTimer(..) is called like so:

AddTimer("step"+1, 0.8 * 1, "CreateFootstep");
AddTimer("step"+2, 0.8 * 2, "CreateFootstep");
AddTimer("step"+3, 0.8 * 3, "CreateFootstep");
...
AddTimer("step"+9, 0.8 * 9, "CreateFootstep");
AddTimer("step"+10, 0.8 * 10, "CreateFootstep");
So what this is actually doing, is creating 10 timers called "step1" through "step10", each waiting 0.8 seconds longer than the previous one. When each of these timers expires the function called "CreateFootstep" is called.

"CreateFootstep" creates a footstep sound in the code shown. Though note that the callback also has an argument which is the timer that actually called the function. This gives you the option to do something on a given footstep. E.g for the 2nd footstep, you could check if "asTimer" was equal to "step2", and perform the actions you wish to perform.
(This post was last modified: 05-07-2011, 05:29 PM by Apjjm.)
05-07-2011, 05:26 PM
Find


Messages In This Thread
Help with "advanced widget script" - by Ge15t - 05-07-2011, 03:19 PM
RE: Help with "advanced widget script" - by Apjjm - 05-07-2011, 05:26 PM
RE: Help with "advanced widget script" - by Ge15t - 05-08-2011, 06:41 AM
RE: Help with "advanced widget script" - by Apjjm - 05-08-2011, 02:32 PM



Users browsing this thread: 1 Guest(s)