BS2 CodingHelp VAR

From FSG Wiki

Jump to: navigation, search

Help Main Menu

Contents

Set or Create a Variable

Syntax:

SET VarName Value

VarName can be anything, but it is CASE SENSITIVE. Value can be any number or operation.

Using a Variable

To use a variable you simply call is name (case sensitive) anywhere in your code. If you misspelled your variable name, this will either return 0 because you use an unexistant variable and BS2 create a new one with default value (0) or you will get the content of the variable you misspelled to. So always check you variable name for case sensitive error.

In the following example i will use TestVAR as the Variable Name.

Example

SET TestVAR 50

Now the variable TestVAR contain the value 50.

SET TestVAR (TestVAR + 1)

Previous example set to variable to 50, now i set my variable to be (50 + 1) so 51. This is to increment a var.

SET TestVAR (WIDTH / 2)

This example will set my variable to half of the width, default width is 420, so (420 / 2)=210.

SET TestVAR 0

This will reset the variable to its default value (0).

SET TestVAR2 120
SET TestVAR1 200
SET TestVAR (TestVAR2 + TestVar1)

Ok here i set 2 new variable at different value, then set my TestVAR to (TestVAR2 + TestVar1). The result would be 120.
You way think i got it wrong, but look carefully

SET TestVAR (TestVAR2 + TestVar1)

I misspelled TestVAR1 for TestVar1 so instead of making (120 + 200), it was making (120 + 0) because TestVar1 wasnt SET before, so its default value is 0. To get it right this is the correct line:

SET TestVAR (TestVAR2 + TestVAR1)

Now TestVAR will be set at 320.

Advanced Example

This is a really usefull function that can return the angle between 2 points. I suggest going here if you want more detail.

REMOVETRIGGER GET_ANGLE
ON GET_ANGLE SET tmpX ($0 - X) 
ON GET_ANGLE SET tmpY ($1 - Y)
ON GET_ANGLE SET tmp (SQRT ((tmpX * tmpX) + (tmpY * tmpY)))

But lets just take it for a good example of variable use. First lets give some variable a value:

  • $0=210
  • $1=210
  • X=300
  • Y=100

Now let's see all line in detail

ON GET_ANGLE SET tmpX ($0 - X) 

This will set tmpX to (210 - 300)= -90 ----> tmpX=-90

ON GET_ANGLE SET tmpY ($1 - Y)

This will set tmpY to (210 - 100)= 110 ----> tmpY=110

ON GET_ANGLE SET tmp (SQRT ((tmpX * tmpX) + (tmpY * tmpY)))

This will set tmp to ((-90 * -90) + (110 * 110)) --> (-8100 + 12100) ---> SQRT(4000)=63 ----> tmp=63
SQRT is the function to get Square Root of a number.

Default BS2 Variables

These are usefull variable you can use anytime in your mod. This goes from the WIDTH of the sandbox to the BRUSHSIZE.
Just take a look here to have a complete liste of those usefull variable. This is a link to Siben's wiki.

Advanced Information

CURSOR - This sets the cursor when over the sandbox

  • 0 - Black Pointer
  • 1 - Transparent
  • 2 - Crosshair
  • 3 - Square
  • 4 - Circle
  • 5 - X
  • 6 - Expand
  • 7 - Scroll
  • 8 - Horizontal Line
  • 9 - Vertical Line
  • 10 - Text

Anything over ten will simply loop in the sequence. The way they are named above does not indicate the use of them; many of them are, by default, unused. Cursors are only for show, not function.

Personal tools