VARIABLE TUTORIAL
There is a very good, short tutorial on variables at DarkHorse Pterid's website. This tutorial, hopefully will go into more depth without all the techy stuff. In fact, a lot of people think they're hard to learn - so much so that you can't even find the variable commands in the DS editor unless you turn your level up to Expert. Don't let variables scare you - they're easy once you take the technoid out of them.
In Furcadia, variables are words that are used to store numbers. They can't store words - they can only store numbers. Variables aren't real smart. This might not seem very handy at first, but it IS because the numbers can change - so if you want object 5, (a blue pillow) one time, and object 8, (a black pillow) the next, you could tell it to remember that variable %pillow equals 5 this time and later you can set it to hold the number 8! Then you use one block of ds to place whatever pillows you want! Handy indeed, don't you think?! I know, you're probably not convinced. It's okay... Variables, once you get past all the techy stuff, are pretty easy. Let's stay out of the spooky techy dictionary and just talk about DS - which we understand!
DS expects a number any place there's an #. Well, any place you can put a number, you can put a variable instead. You can add, subtract, multiply or divide variables, and you can move them according to so many steps this way or that...
Variable names always start with %. The % tells Furcadia that the next word is a variable. Variable names can be up to 8 characters long using A-Z or a-z. They are case sensitive - which means that %box is different than %BOX. You can have up to 500 variables in a dream. You can even emit a variable, like 5:200 emit {There have been %visits visitors since last upload.} to the triggering furre. If you want to emit just the number, put a space in after the variable name like emit { %SomeVar } .
Positions in DS are usually (#,#). The first number is the X position of the tile you want and the last one is the Y position of the tile you want. Variables for positions are a little different. You see, Fel wanted to make it easier on us by allowing us to just have ONE variable for that two number position - so we could say "Move the triggering furre to %SomePos." And so he came up with this:
%SomePos.x %SomePos.y
Did you see the .x and the .y? When those are set, (%SomePos) is the same as (%SomePos.x , %SomePos.y) which is the same as (#,#).
Very smart techy furres have used this to move positions mathematically. If you look at a map in dream ed, you'll see that positions that go from SW to NE go up in increments - the X goes up like this 10, 10, 12 , 12, 14, 14, 16, 16, etc. While the Y goes down by 1 each time like this: 36, 35, 34, 33, 32.... Knowing this tiny bit of info (and having a degree in Algorythmathematical Techese) can help you locate a random tile in a specific area, or drive a boat along. It's a bit out of the scope of this particular tutorial and would make your head hurt, so we'll leave that for later, but understand that you can use a variable to store an X and a Y at the same time.
So let's let's actually use some variables so you can see what good they are and how it all fits... I've decided to put in a dresser (Object 185) that will spit out random treasure. And because I know how this works, heh, I'm going to make the treasure objects 45 through 53 (the drum all the way through to the pookie) - that's 9 objects. So I get the DS ready:
(0:3) When somebody moves into object type #,
(5:312) set variable # to the total of rolling # dice with # sides plus #.
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type #.
Okay, so now we'll fill it out:
(0:3) When somebody moves into object type 185,
(5:312) set variable %treasure to the total of rolling 1 dice with 9 sides plus 44.
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type %treasure.
That second line looks difficult, does it? Well, I'm going to set the %treasure variable by rolling a dice to give me a random number. That random number needs to equal an object number. Since there are 9 objects, I'm going to roll one 9-sided die. The treasure objects I'm using start at object 45, and you can't roll a 0 on a dice, so I'm going to add 44 to the result - so the rolls will be some number between 44+1 (45) and 44+9 (53). I know it looks an awful lot like sleeping through math class was a mistake, doesn't it...
One of the things you'll have to remember is that you must set the variable before you can use it. If you use a variable before you set a number to it, Furcadia gets confused because the variable doesn't have a number in it.
Now you could also count visitors and emit how many people have been in a dream:
(0:0) When everything is starting up,
(5:300) set variable %visits to the value 0.
(0:9) When a furre arrives in the dream,
(5:15) move the triggering furre to (10,10), or to someplace nearby if it's occupied.
(5:302) take variable %visits and add 1 to it.
(0:31) When a furre says {stats},
(5:200) emit message {There have been %visits visitors since we last uploaded.} to whoever set off the trigger.
When everything starts up means when the dream is first uploaded... you have to set the variable before you can use it, and since the dream will want to use %visits when anyone arrives in the dream, you have to set it before anyone arrives - that's when the dream is uploaded!
When a furre arrives, move them to some place - then add 1 to the number you have stored in %visits. The first person in will cause %visits (which holds 0) to add 1 to it (making %visits = 1) The next person in will add one to that, so %visits will equal 2, and so on.
And finally when someone says "stats", the dream will emit the message and replace %visits with the number it holds.
The last thing we should cover today is position variables. You can set positions into variables via ds by using these lines:
(5:350) set variable # to the X,Y position the triggering furre (moved
from/is standing at).
(5:351) set variable # to the X,Y position the triggering furre moved to.
(5:500) set variable # to the X,Y position of a random spot within the rectangle
(#,#) - (#,#),
(5:501) set variable # to the X,Y position of a random spot that is onscreen
for the triggering furre,
(5:502) set variable # to the X,Y position of a random spot somewhere in
the dream,
(5:510) set variable # to the X,Y position of a random spot where the floor
is type # within the rectangle (#,#) - (#,#),
(5:511) set variable # to the X,Y position of a random spot where the floor
is type # that is onscreen for the triggering furre,
(5:512) set variable # to the X,Y position of a random spot where the floor
is type # somewhere in the dream,
(5:520) set variable # to the X,Y position of a random spot where the floor
is not type # within the rectangle (#,#) - (#,#),
(5:522) set variable # to the X,Y position of a random spot where the floor
is not type # somewhere in the dream,
(5:530) set variable # to the X,Y position of a random spot where the object
is type # within the rectangle (#,#) - (#,#),
(5:531) set variable # to the X,Y position of a random spot where the object
is type # that is onscreen for the triggering furre,
(5:532) set variable # to the X,Y position of a random spot where the object
is type # somewhere in the dream,
(5:540) set variable # to the X,Y position of a random spot where the object
is not type # within the rectangle (#,#) - (#,#),
(5:541) set variable # to the X,Y position of a random spot where the object
is not type # that is onscreen for the triggering furre,
(5:542) set variable # to the X,Y position of a random spot where the object
is not type # somewhere in the dream,
You can also set positions this way:
(5:300) set variable %space.x to the value 20.
(5:300) set variable %space.y to the value 40.
Which means you can then use %space for any place where you need to write (20,40).
Well, this should get you well on your way to learning variables... Next lesson, that sneaky random XY math and arrays!
