Functions Parameters

From FSG Wiki

Jump to: navigation, search

Back to Main Page

Easy Example 1

Lots of people are getting confused by all the $0 $1 $2 ... in new BS2 function.

I'll try to explain this so it is easy to understand.

First, let's check this simple piece of code:

 REMOVETRIGGER MyFunction
 ON MyFunction SET rcvdParam0 $0
 ON MyFunction SET rcvdParam1 $1
 ON MyFunction SET rcvdParam2 $2
 ON MyFunction SET rcvdParam3 $3
 ON MyFunction SET ResultOfMyFunction ((($0 + $1) - $2) + $3)

Ok so this function, receive 4 parameters. Each $ is a parameters.
The SET rcvdParam part is only for easier understanding. So lets call the function like this:

 EXEC MyFunctions 10 20 30 40

So when the function is executed

  • rcvdParam0=10 ($0)
  • rcvdParam1=20 ($1)
  • rcvdParam2=30 ($2)
  • rcvdParam3=40 ($3)

Then the last line is what the function do so lets make the calcul:

  • (((10 + 20) - 30) + 40) = 40

So after the function was executed with the given parameters, "ResulOfMyFunction" will contain the value 40.


Easy Example 2

This is a function from my cannonball mod, what it do is set a variable to 1, then set a timer to reset it to 0.

 REMOVETRIGGER FREEZESHOT
 ON FREEZESHOT SET SHOOTINGisFREEZED 1
 ON FREEZESHOT TIMER $0 FRAMES UNFREEZESHOT
 REMOVETRIGGER UNFREEZESHOT
 ON UNFREEZESHOT SET SHOOTINGisFREEZED 0

This function is very simple, it only receive 1 parameter and it correspond to the number of frames you want to set the timer to.
So lets say i call the function like this:

 EXEC FREEZESHOT 30
  • First it set SHOOTINGisFREEZED to 1
  • Then it set a timer to $0 Frames, $0 being the first parameter (and only) so $0=30.
  • So it set a timer at 30 Frames to execute UNFREEZESHOT.
  • 30 frames after, UNFREEZESHOT is executed, and SHOOTINGisFREEZED is set to 0.
Personal tools