Variables & Arrays - Tutorial
Free Counters

What are variables?
What are arrays?
Random-Spot Variables
Other Things To Note

 

What Are Variables?

A variable is kind of a miniature database, this "database" however, can only store numbers,
but can handle any value between
-32768 & 32767, This is plenty of space for just about any variable value.

Note: Something to take care of in variables, is that they are CASE-SENSITIVE If you create one variable
in all capitals, then make the final effect that uses the same
variable, but in all lower-case letters, The code will not work.


(5:300) set variable %dragon to the value 7.


The above line is an example of the lines you will find when on the Expert Difficulty setting
the line describes to the server that the variable %dragon is to be given the value of 7.

Now, the variable %dragon will keep that value of 7, until it is changed by another effect.
You can now use this variable for most lines that require numeric input.

So for example you could use a timer that was automatically triggered after "seconds delay"

(0:100) When %dragon seconds have passed, offset by 0.

The above line will work the same way as making the input - (0:100) When 7 seconds have passed, offset by 0,
But, by using a variable this allows for the input to be changed at any time

Variable-seconds, can be used to trigger effects at different times, rather then messing around with different lines :)

Below is an example of a code that can be used to change the value of variable %timer - effectively allowing the
trigger to work at different-times, so you could start out with 3 seconds between each trigger of changing a pillows colour
by changing that value to 10, it would then be 10 seconds between each trigger of changing the pillows colour.

(0:0) When everything is starting up,
(5:300) set variable %timer to the value 3.

(0:32) When a furre says something with {settimer } in it,
(5:314) set variable %timer to the number the triggering furre just said.

(0:100) When %timer seconds have passed, offset by 0,
(5:6) swap object types 4 and 5.


When a furre says something with "settimer " in it, the variable %timer would be changed to the number the triggering furre stated,
So if they said "settimer 17" - the value of %Timer would be changed to 17, and the pillows would swap every 17 seconds.


You can use variables for more then just Timers however, you can use them for objects too!

(0:0) When everything is starting up,
(5:300) set variable %object to the value 59.

(0:7) When somebody moves into position (14,16),
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type %object.


As we can see from the code above, when everything is starting up [uploading] the variable %Object is set to the value of 59.
Then, when somebody moves into the position 14,16, where the triggering furre moved from, the object type %Object would be placed.
In this case that object would be the Blue Egg, object number 59, Using any number of commands this value can be changed:

(5:302) take variable %object and add 101 to it.

This would then mean the object number was 160, a Pink Egg, when a furre moved into position 14,16, where
they moved from the object number 160 would be placed, Again with any number of commands, this value can be changed
back down to its original value (Be sure to NOT use the same code as before!)

(5:304) take variable %object and subtract 101 from it.

This would then mean the object number was back to its original value of 59.
More codes have been discovered since then however, including a code to create an item, that the furre had chosen
without the requirement of making the same code for -every- item. ;)

(0:32) When a furre says something with {MakeItem } in it,
(1:11) and the triggering furre has got shared control (or is the dream owner),
(5:314) set variable %item to the number the triggering furre just said.
(3:7) where the triggering furre is currently at,
(5:4) place object type %item.

The above code is the one used popularly to create an item, based on the object number a shared furre states.
For example, if a shared-users says "makeitem 1", where they stand object type 1 would be placed.
How this works, is when they say something with makeitem in it, if a number was stated after it, that number would be
placed into the variable %Item  then object type %Item would be placed.


Note that variables can also store Positions, these can be done in two ways. -- 

Pre-Set                              &                              Trigger-Set


Firstly i shall cover Pre-Set variable positions, this can easily be done using set-variables.

(0:0) When everything is starting up,
(5:300) set variable %loc.x to the value 35.
(5:300) set variable %loc.y to the value 74.

The code above is the same as Position (35,74) but instead of entering (35,74) as a position.. you can use for example

(0:7) When somebody moves into position (%Loc.x,%Loc.y),

This can be useful instead of putting 35,74 continuously over and over, But you can however use the code to track locations

(0:1) Whenever somebody moves,
(1:19) and they (moved from/are standing at) position (%track.x,%track.y),
(1:70) and their name is {Furre},
(3:5) where the triggering furre (moved from/is standing at),
(5:350) set variable %Track to the X,Y position the triggering furre (moved from/is standing at).

With that, the user "Furre"'s location would be tracked and updated in variable %Track whenever they moved from its previous location,
This can be useful in any number of ways.

The above code example also shows the line
(5:350) set variable %track to the X,Y position the triggering furre (moved from/is standing at).
this line as well as
(5:351) set variable # to the X,Y position the triggering furre moved to.

These two lines are Trigger-Set position variables, an example of these has already been given.
The example tracks the movement of the user "Furre" whenever that user moved from the location already set

The "tracking" can begin from any number of ways, ranging from voice commands to moving into a position or object.
For example

(0:31) When a furre says {TrackOn},
(1:11) and the triggering furre has got shared control (or is the dream owner),
(5:350) set variable # to the X,Y position the triggering furre (moved from/is standing at).


That should be enough to get you started, next we'll move onto Array-Variables.

#Back To Top


What Are Arrays?

Arrays are basically, one huge variable.  They hold multiple values...
Say for example, you wanted to "memorize" 5 object codes for different voice commands
but didn't want to mess around naming 5 different variables.

Why not try an Array?

(5:311) use variable %memory[5] as an array, and set element 1 of it to 5.
(5:311) use variable %memory[5] as an array, and set element 2 of it to 7.
(5:311) use variable %memory[5] as an array, and set element 3 of it to 8.
(5:311) use variable %memory[5] as an array, and set element 4 of it to 15.
(5:311) use variable %memory[5] as an array, and set element 5 of it to 16.

"%Memory[5]" means basically - "an array called %Memory, which has a total of 5 different elements of that variable, that you can put values into."
You'd change the number within the brackets to whichever amount of elements you hold within that variable.

So if you wanted 9 elements to %Memory, you'd call it %Memory[9] .

So, putting these codes into effect, as i mentioned earlier if you wanted to set different voice commands to get items, you'd use a code like:

(0:31) When a furre says {Gimme a green pillow},
(5:310) use variable %memory[5] as an array, and copy element 4 of it into variable
%object.
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type %object.

(0:31) When a furre says {Gimme a yellow pillow},
(5:310) use variable %memory[5] as an array, and copy element 5 of it into variable %object.
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type %
object.

And so on, but do not however forget to change the element number on (5:310)

The line (5:311) use variable # as an array, and set element # of it to #.  copies the set-element from the array, into a variable
This variable is usually referred to as a "dummy variable" - a kind of storage variable when using a value from an array's element
in an effect-trigger, this can be used like the way above to create a kind of pre-set Inventory system.

Array's are even more useful then that, as we can use other variables to tell the array what element to use.

(5:310) use variable %memory[5] as an array, and copy element %Which of it into variable %object.
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type %
object.

Using this method, it is also possible to set which element to create manually, again using voice commands

(0:32) When a furre says something with {OpenBox } in it,
(5:314) set variable %Which to the number the triggering furre just said.
(5:310) use variable %memory[5] as an array, and copy element %which of it into variable %object.
(3:5) where the triggering furre (moved from/is standing at),
(5:4) place object type %object.

Effectively allowing a user to "open" a box [element] they specify to receive the item within, Although this item can only be set
on the dragonspeak and not later in furcadia as at this time you cannot put the value from a variable into an array.

Don't worry about understanding the code above however, that part can be considered Extremely Complex, which even some of the
"experts" do and will struggle at from time to time.

Moving on, we have rectangle-variables.


#Back To Top


Random-Spot Variables

Some of the new variables with V03.00 DragonSpeak work directly with
Random-Spots; These include:

Rectangles
Onscreen for the triggering furre
Somewhere within the dream

There are 5 different variances to each of these codes:

* Normal, works regardless
* "Only where the floor type is type #"
* "Only where the floor type is NOT type #"
* "Only where the object type is type #"
* "Only where the object type is NOT type #"

The following three codes work regardless of the item or floor within their area.

(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,


Note: At this time all the variables to do with rectangles are currently bugged, and do NOT appear to work correctly
regardless of any attempt made to bypass them while still using the variables to get the random position.


The first line, selects random spot within the area of a specified rectangle, and inserts the chosen location into a variable      (bugged)

So, using the line (5:500) set variable %rectangle to the X,Y position of a random spot within the rectangle (17,19) - (32,34),    [Example.]
Will select a random location within the rectangle 17,19 - 32,34 and place the values of that position into %rectangle,  the X value is inserted
directly as %rectangle.x  while the Y value is inserted directly as %rectangle.y  You can however just use %rectangle as the POSITION when selecting the space for an effect to be triggered, So for example if you wanted to place an object at random within the rectangle, but removing the older one
a code sample would be ->

(0:100) When 1 seconds have passed, offset by 0,
(5:500) set variable %rectangle to the X,Y position of a random spot within the rectangle (17,19) - (32,34),
(4:3) only where an object type 389 is,
(5:4) place object type 0.
(3:2) at position (%rectangle) on the map,
(5:4) place object type 389.

The line (5:510) set variable # to the X,Y position of a random spot where the floor is type # within the rectangle (#,#) - (#,#),
Works in the same way but the random spot will be set ONLY where the floor type is the type specified, So if you use floor type 8
But have floor type 10 present within the rectangle you use, the random location will ONLY effect the type 8s, while all others
are not effected by the code - Whilst the line
(5:520) set variable # to the X,Y position of a random spot where the floor is not type # within the rectangle (#,#) - (#,#),
will ONLY effect the floors that are NOT of the one specified, so if the floor type you set was floor type 10
Only those floors that were not floor type 10 in the rectangle would be affected.

Once more, the line (5:530) set variable # to the X,Y position of a random spot where the object is type # within the rectangle (#,#) - (#,#),
works the same way as the (5:510) line about floors - the code will ONLY select random spots where the object type is # within the rectangle, all other objects will be ignored - Whilst the line (5:540) set variable # to the X,Y position of a random spot where the object is not type # within the rectangle (#,#) - (#,#),   will ONLY effect the objects that are NOT of the one specified, so if the object type you set was 59, and you also had object types 160 within that rectangle, only the 59's would be chosen as the random position.

So, the floor & object lines seem to have a "built-in" Filter.

#Back To Top


Onscreen Random Spots. (works)

(5:501) set variable # to the X,Y position of a random spot that is onscreen for the triggering furre,
(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:521) set variable # to the X,Y position of a random spot where the floor is not type # that is onscreen for the triggering furre,
(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: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,

The above lines work under the same conditions as setting a rectangle, but cannot be triggered by a timer - of any kind.
Below is an example of when a triggering furre walks into a set position, and move into object type 66, in the space that furre can see
the object 160 (blue egg) is created - whilst removing the old

(0:7) When somebody moves into position (12,22),
(1:3) and they move into object type 66,
(5:501) set variable %onscreen to the X,Y position of a random spot that is onscreen for the triggering furre,
(5:5) change object type 160 to type 0.
(5:41) place object type 160 at (%onscreen).


#Back To Top


Somewhere Within The Dream.
 (works)

(5:502) set variable # to the X,Y position of a random spot somewhere in the dream,
(5:512) set variable # to the X,Y position of a random spot where the floor is type # somewhere in the dream,
(5:522) set variable # to the X,Y position of a random spot where the floor is not type # somewhere in the dream,
(5:532) set variable # to the X,Y position of a random spot where the object is type # somewhere in the dream,
(5:542) set variable # to the X,Y position of a random spot where the object is not type # somewhere in the dream,


Once more the above lines work under the same conditions as setting a rectangle, but can be triggered by timers.
Below is an example - At a random location somewhere in the dream (anywhere)
a monster (object type 262) is created every 5 seconds (only 1 at a time) - Perfect for "spooky" dreams!

(0:100) When 5 seconds have passed, offset by 0,
(5:502) set variable %somewhere to the X,Y position of a random spot somewhere in the dream,
(5:5) change object type 262 to type 0.
(5:41) place object type 262 at (%somewhere).


#Back To Top


Other things to note.


* Emitting the values from variables

(5:200) emit message {The current score is %score } to whoever set off the trigger.

** If the variable is at the very end of the emit, be sure to keep a space right at the end, this will prevent conflict.
** You cannot emit an array in emits.



* Exceeding the value limits in limits will cause the emit to bug and give a random value.

**Example**

Take a value of 30000, and add 10000 - after exceeding the limit of 32767 it will revert back to -32768 and add the rest of the value.
So, with a value of 30000, and adding 10000 to it -- 2767 of it will be added to that value until it reaches its limit, then it will use 1
to switch to the Minus values, at this point it will have used 2768, leaving 7232 left over, that 7232 is then taken away from -32768
until we get the value of -25536 This, in effect is a continuous cycle, meaning if we have 30000 and add 100000, it will be reverted back
to -32768  leaving 97232 left over, 65535 of that 97232 is then used to fill the value back to 32767, where another 1 is used to revert it back
to -32768 once more, that leaves -- 31696 All of that is then added onto -32768 to give us the final total of -1072.

 

#Back To Top
 



Back Home


http://www.mysticallands.com/tutorials/
 

This page was created by mysticsentry, as a tutorial guide to players learning dragonspeak variables - Both New & Old Users.
Furcadia is a multi-user online chat system that has multiple things to do, even try your hand at dreams and patching

Virtual Pets | Games

Release The Furre Within - Furcadia!

Furcadia.com - Don't Delay, Join Today!