SRL Archive - OSR Outdated Tutorials

Variables!


Smarter Child

2009-09-02 04:01:43

Variables!

Hi welcome to my really small tutorial on variables

What are variables?? Variables are like containers, you can put things in variables (containers).

Lets start by learning how to declare a variable:

Code:
[LEFT]program Variables;

var //this is a global call of variables, which means its not in a procedure or function
//and can be used anywhere in the entire script

Procedure Blah;
begin
end;

begin
end.
[/LEFT]


So thats the word, you use to start declaring the variables,

Most common Types*(thx richie :)):

Integers - These are whole numbers, negative or positive: -1 or 637387
Strings - These are words or letters: HALLELUJAH
Booleans - These are like results, true or false [yes or no]
Extended - These are numbers extended pass the decimal point: 456.33 or 0.222256

So that's what variables can be declared as, the name of the variable can be anything for example"

Code:
[LEFT]Var
smarterchild: integer;
[/LEFT]


When to use variables?

Well variables is an aspect of scripting that will come up a lot, you cannot avoid them totally :p.

Examples of variables:

- Coordinates: x/y are very common as integers to hold coordinates
- Colors: These are integers

Some basic usage of variables:
Code:
[LEFT]program New;
var
s: string; //declares s as a string

begin
s := 'HELLO WORLD'; //assigns 'HELLO WORLD' to the s variable
cleardebug; //clears debug box
Writeln(s); //writes s aka 'HELLO WORLD' into the debug box
end.
[/LEFT]


Code:
[LEFT]program New;
var
x, y: integer;
begin
if FindColor(x, y, 436737, 1, 2360, 80, 2337)then //if it finds the color it does below
MoveMouse(x, y); //moves the mouse to the x/y position
end.
[/LEFT]


Ce:
[LEFT]program New;

var
deci: extended; //deci is an extended value
RoundedNumber: integer; //roundednumber is an integer value
begin
deci := 0.2222; //assigns deci to 0.2222
RoundedNumber := Round(deci); //assigns RoundedNumber to Round(deci) which results as an int
Writeln('Rounded Number: ' + IntToStr(RoundedNumber)); //Writes in rounded number by //converting the RoundedNumb integer value to a string
//THIS EXAMPLE IS A LITTLE HARD, SO IF U DONT UNDERSTAND ITS ALRIGHT
end.
[/LEFT]


Thanks for reading, i hope you now know how to use variables ;).

:).

~~ END ~~






Rick

2009-09-02 04:23:46

Nicely done! Easy to understand. :)
Some Suggestions:
Most common classes(i think thats what they're called):

"Types", is the word you're looking for.

You should put some code tags in there just too make it easier to look at.
And maybe mention that a string isn't only letters, but characters including "!@##$ abcd 123" ?
You could also explain
IntToStr(RoundedNumber))
a little more, so as to not confuse beginners by jumping into something.

Smarter Child

2009-09-02 05:27:10

Yah, i used the wrong editor mode, and it screwed up :confused: