Scar Tutorial: Basic Variables

Discussion in 'Code Snippets and Tutorials' started by Billy, Mar 22, 2007.

  1. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    To understand this tutorial, you need a basic knowledge of scar.

    What Is A Variable?
    a variable is something that changes in the program variables can be used to store numbers or letters and even more. There are three main types of variables, Integers, Booleans, and Strings. With integers, the variable can store any whole number (a number without a decimal). Booleans have two modes and only two modes , those modes are true and false. Strings store letters and words and even sometimes numbers.
    How Do I Make A Variable?
    you can make all three types of variables in similar ways. Here are the ways

    Integers:
    Code (Text):
    1. program New;
    2. var FirstVariable: Integer;
    3.  
    4. begin
    5. end.
    6.  
    var tells the program that you are going to make a variable. after that, you put your variable's name. Variables must have a one-worded name. Then after the colon, you put the type of variable you want it to be. In this case, we want to make an integer, so i put integer after the colon.

    Booleans:
    Code (Text):
    1. program New;
    2. var Boolean1: Boolean;
    3.  
    4. begin
    5. end.
    everything else is the same as in the integer, except after the colon it tells the program that we want this variable to be a boolean.

    Strings:
    Code (Text):
    1. program New;
    2. var string1: String;
    3.  
    4. begin
    5. end.
    The same as the last two, except now i am telling scar that i want the variable to be a string.


    How Do I Use Variables?

    To use variables, you need to store something to it. here are a few examples.

    Integers:
    Code (Text):
    1. program New;
    2. var integer1: Integer;
    3.  
    4. begin
    5. integer1 :=(random(15));
    6. writeln(inttostr(integer1))
    7. end.
    that script will get a random number between 1 and 15 and store it to 'integer1' then it will display the value of the integer.

    Boolean:
    Code (Text):
    1. program New;
    2. var boolean1: Boolean;
    3.  
    4. begin
    5. case random(2) of
    6. 1: boolean1 :=true;
    7. 2: boolean1 :=false;
    8. end;
    9. if boolean1=false then
    10. writeln('no');
    11. if boolean1=true then
    12. writeln('yes')
    13. end.
    this script will generate either 1 or 2 if its one, then the script will store true to boolean1, if its 2 it stores false to boolean1.

    String:
    Code (Text):
    1. program New;
    2. var string1 :string;
    3.  
    4. begin;
    5. string1 :='Hi people.';
    6. writeln(string1);
    7. end.
    This stores " Hi people" to a string1 and then displays string1.


    How Do I Store Something To A Variable?


    To store something to a variable, just tell it what the variable "=" if "variable1" was an integer i might do something like this
    Code (Text):
    1. variable1 :=13455
    If it were a string, i might do
    Code (Text):
    1. variable1 :="Hello World"
    Finally, if it were a boolean,
    Code (Text):
    1. variable1 :=true
    How Can I Check A Variables Value?

    To check a strings value, all you have to do is put the string to a 'writeln' command like this
    Code (Text):
    1. writeln(string1);
    For integers, you do the same thin, just you need to convert it into a string like this
    Code (Text):
    1. writeln(inttostr(integer1));
    For booleans, you need to do something a little more complex
    Code (Text):
    1. if boolean1 :=true then
    2. writeln('true');
    3. if boolean1 :=false then writeln('false')


    I hope you liked my tutorial, my next one will be on procedures(i didnt have enough room in this one)
     
  2. chelsea1

    chelsea1 Level IV

    Joined:
    Nov 26, 2006
    Messages:
    2,538
    Likes Received:
    31
    Location:
    London
    ok but i think you need to put at the top that you need to have basic scar knowledge to use
    also, i think it would be better if you had better code examples
    i say this without looking, but i suspect that you would get a better grasp of variables if you just read the standard tutorials (general ones) or better still downloaded the scar tut in vb
    saying that though,for a first tutorial that isn't bad although if i were to redo it i would talk about things like bitmaps needing variables and how you can use variables in clickmouse commands (after bitmaps or findcolors)
     
  3. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    it is supposed to be a basic scar variables tutorial. i thought that if you knew how to use bitmaps and how to do codes more advanced than the examples i included, you would be beyond this tutorial.
     
  4. chelsea1

    chelsea1 Level IV

    Joined:
    Nov 26, 2006
    Messages:
    2,538
    Likes Received:
    31
    Location:
    London
    ok then i take it back
    it is a good first tutorial and a good introduction to variables
     
  5. Underground_Secrets

    Joined:
    Dec 22, 2006
    Messages:
    626
    Likes Received:
    1
    Gender:
    Female
    Location:
    West Coast in USA
    i only understood about half of that. :? i know wat var means. its the function ure gonna use basiclly. then u put the name of the fuction & there r 3 but im still not sure wat they all do? can u give more examples?
     
  6. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    it tells what they do, but i will explain it more. a integer stores only numbers so you use integers if you want to store anything that is a number for later use. a string holds sentences and words they can be used to hold bitmaps and basicaly anything else ans long as you put it in apostrophes 'like this'. booleans are very simple, they are either true or false, a lot like binary, where everything is either on or off, or like answering a yes or no question, no flexibility, either true or false. they are just used to store a value to a later place and are designed to change when necessary. i hope i answered all of your quenstions.
     
  7. Underground_Secrets

    Joined:
    Dec 22, 2006
    Messages:
    626
    Likes Received:
    1
    Gender:
    Female
    Location:
    West Coast in USA
    so they both achieve the same gola they just have a different way of doing it?