Author Topic: Tutorial on Variables  (Read 966 times)

[size=18]Variables[/size]

Think of variables as items that you can't pick up or do anything with without events. There are pretty much two types of Variables, Client and Player variables. Client variables stay with you when you die, and player variables disappear when you die. When doing anything with variables, make sure you are always using the same Client/Player with that variable. For instance, if I had a variable called coins, and they were a Client variable, then all events using coins must be Client, not Player or Self, all of which I will explain later.

Note, most variable actions also have a self target, it targets the brick the event is on.

AddVariable
I believe this can be used with inputs like OnActivate, or OnPlayerTouch, which require a player directly interacts with the brick. It can also be used with events like OnRelay, which do not have a player's direct interaction, although I'm pretty sure it will only give you the Self addvariable "Target".

Anyway, about the addvariable event itself, an addvariable event basically looks like this: OnActivate > Client > Addvariable > [               ]  [              ]
In the two boxes at the end you put the variable to add, and the amount to add. You can use a negative number to subtract from the variable. Beware though, you can get negative variables, unless you use the IfVariable event explained later. Here is an example of a fully filled in addvariable event.
OnActivate > Player > AddVariable > [Fish      ]  [1       ]
This event will add one variable called Fish, however, it will not tell people that they gained one, so you might want to use a center/bottom/chatmessage to inform them that they gained one, or use the DisplayVariable event explained next.

DisplayVariable
This basically displays how many of a variable someone has. This is usually used with the addvariable event, but not always. It will always look like: *variablename* is *amount*. There isn't a way to change it that I know of. The variable can be displayed as CenterPrint, BotomPrint or ChatMessage. Displayvariable is located in client. A displayvariable event looks something like this:

OnActivate > Client > Displayvariable > Client > CenterPrint > Fish  [3]

A breakdown of that: The onactivate is obvious, client same, so is Displayvariable. The second client says that the variable is a ClientVariable, as opposed to a player variable. Centerprint tells it to display the variable in the center, and fish is the variable to display. The box with the number is how long it will display (in seconds).

DivideVariable
DivideVariable is like addvariable except that it divides the variable instead of adding to it. Unlike addvariable, though, putting in a negative number will not cause it to multiply. This is an example of a dividevariable event:
OnActivate > Client > Dividevariable > [Fish] [10]
This divides the Client Variable called Fish, by 10, thats about it for dividevariable.

IfVariable
You would find ifVariable in the brick target, and then set the target of which variable to check. IfVariable is a bit more complicated, it pretty much tests whether the Variable fits the requirements. Doesn't make sense? Check out the example.
OnActivate > Self > IfVariable > Client > Fish > GreaterEquals > 42
Now, onactivate is pretty self explanatory. The IfVariable event is under the Self target. The Client tells you that it is a Client Variable we want to test, fish is the name of the variable. GreaterEquals means it is testing whether the number is Greater or Equal to 42. The other ones you can use are: Equals, NotEquals, Greater, Less, and LessEquals. Simple, really. After the actual test event, use VariableTrue and VariableFalse to say what happens, here is an example.

OnActivate > Self > IfVariable > Client > Fish > GreaterEquals > 42
VariableFalse > Client > CenterPrint > [Not enough fish]
VariableTrue > Client > CenterPrint > [Wow, you have a lot of fish!]

Conclusion
That covers pretty much everything about variables, but the best way to learn them is probably to use them, so get out there and event, event, event. Some things you might want to try are: Make a levelable mining system, or a mining system that uses Mining Exp, a combintion lock that uses variables. Or make a class leveling system out of variables. Those are just a few ideas, though. Just a few things before I finish, I don't claim to be the absolute expert on variables, so there may be a few mistakes. I'm also sorry if this is the wrong place.
Thanks, Wizard, signing off.

Thanks
jaxx050 and Amade on the RTB forums for pointing out that I forgot to tell you the ifVariable is a self target and Chrono for actually making them.

Sorry about any BBCode bugs, since I copied this off RTB.

Sorry about any BBCode bugs, since I copied this off RTB.

so... why not just give us a link to RTB? >:I

Someone on there wanted me to post it here.

You can make it cooler by naming variable names like

The amount of Gold in your pack

so when you display it,

The amount of Gold in your pack is #

ect.

Someone on there wanted me to post it here.
Like me. I'll ask Dest. to link to this as a basic tutorial.

That would be awesome.

You should also mention brick variables. They have their own uses.

You can't modify here? :< Whatever. You should also mention, for events about player inventories, you should use the player variables. Client variables work for everyone. (I believe)