RSS | Roulette Scripter Studio | Lesson 5 | If, if else, Case, relational operators
     
This tutorial was made by Silver
http://www.money-maker-machine.com/forum/profile/Silver/
 
Lesson 5. If, if else, Case, relational operators. Logical Operators and Boolean Expressions.
 
I.
IF statement.


The if statement allows a program to make a decision based on a condition. The IF statement allows you to branch based on the result of a Boolean operation.
The one-way branch format is:

if BooleanExpression then StatementIfTrue;

If the Boolean expression evaluates to true, the statement executes. Otherwise, it is skipped.

Ex.5.1: The following example make a spin and tell us if landed number is High:
var landed_number;
begin
    set_roulette_window_name('European Roulette - onlineCasino.com');
    click_spin();
    landed_number:=get_last_number();
    if landed_number >=18 then print('Landed number is High');
end;


In case more than one action is required, you must use a begin-end to enclose the statements:
if BooleanExpression then begin
  Statement1;
  Statement2;
  ...
end;


Ex.5.2: The following example make a spin, tell us if landed number is High, and in case it is High - will bet chip2 on Low.
var landed_number;
begin
    set_roulette_window_name('European Roulette - onlineCasino.com');
    click_spin();
    landed_number:=get_last_number();
    if landed_number >=18 then begin
      print('Landed number is High');
      print('Will bet chip nr.2 on Low');
      click_chip2();
      click_low();
      click_spin();
    end;
end;


II.
Relational operators.


Here is a table of the operators than can be used in conditions:

  >      Greater than
  <      Less than
  >=    Greater than or equal to
  <=    Less than or equal to
  =      Equal to
  <>    Not equal to

III.
IF with else

The above example 5.1 only tells you if the number is High. If you want it to tell you that it is not High then we use else .

if BooleanExpression then StatementIfTrue
                                        else StatementIfFalse;

note: When you use else you must not put a semi-colon on the end of the command before it.

Ex.5.3: The following example make a spin and tell us if landed number is High or no:
var landed_number;
begin
    set_roulette_window_name('European Roulette - onlineCasino.com');
    click_spin();
    landed_number:=get_last_number();
    if landed_number >=18 then print('Landed number is High')
                                                else print('Landed number is not High - it is Low or Zero');
end;


In case more than one action is required after else, you use a begin-end to enclose the statements:

Ex.5.4: The following example make a spin, tell us if landed number is High, and in case it is High - will bet chip2 on Low, in case it is not High - will bet chip2 on High.
var landed_number;
begin
    set_roulette_window_name('European Roulette - onlineCasino.com');
    click_spin();
    landed_number:=get_last_number();
    if landed_number >=18 then begin
      print('Landed number is High');
      print('Will bet chip nr.2 on Low');
      click_chip2();
      click_low();
      click_spin();
    end else begin
      print('Landed number is not High - it is Low or Zero');
      print('Will bet chip nr.2 on High');
      click_chip2();
      click_high();
      click_spin();
    end;
end;


And because the operator click_spin() will e executed anyway - we may write it once instead of write it in 2 positions.
Ex.5.4.1: The following example make a spin, tell us if landed number is High, and in case it is High - will bet chip2 on Low, in case it is not High - will bet chip2 on High.
var landed_number;
begin
    set_roulette_window_name('European Roulette - onlineCasino.com');
    click_spin();
    landed_number:=get_last_number();
    if landed_number >=18 then begin
      print('Landed number is High');
      print('Will bet chip nr.2 on Low');
      click_chip2();
      click_low();
    end else begin
      print('Landed number is not High - it is Low or Zero');
      print('Will bet chip nr.2 on High');
      click_chip2();
      click_high();
    end;
    click_spin();
end;


IV.
Nesting IF statements.

You can also use IF statements inside other IF statements.

if Condition1 then
  Statement1
else
  if Condition2 then
    Statement2
  else
    Statement3;


Be careful with nesting. Sometimes the computer won't do what you want it to do:
if Condition1 then
  if Condition2 then
    Statement2
else
  Statement1;


The else is always matched with the most recent if, so the computer interprets the preceding block of code as:
if Condition1 then
  if Condition2 then
    Statement2
  else
    Statement1;


You can get by with a null statement:
if Condition1 then
  if Condition2 then
    Statement2
  else
else
  Statement1;


or you could use a begin-end block.
if Condition1 then begin
  if Condition2 then Statement2;
end else Statement1;


But the best way to clean up the code would be to rewrite the condition.
if not Condition1 then
  Statement1
else
  if Condition2 then Statement2;


V.
Case..of

The case command is like an if statement but you can have many conditions with actions for each one.

Suppose we have to select what dozen to bet. Say, we have 3 options based on dozen number, and 0 is Zero. The if example would be like this:

if dozen=1 then
  click_first_dozen_bet()
else   { remain dozen2, dozen3 and 0 }
  if dozen=2 then
    click_second_dozen_bet()
  else   { remain dozen3 and 0 }
    if dozen=3 then
      click_third_dozen_bet()
    else   { 0 goes here }
      click_straight_up_0();


This is pretty long. Now see this:

case dozen of
    1: click_first_dozen_bet();
    2: click_second_dozen_bet();
    3: click_third_dozen_bet();
    else click_straight_up_0();
end;

Simple and elegant !

In case more than one action is required, you must use a begin-end to enclose the statements:

case dozen of
    1: begin
          click_first_dozen_bet();
          click_first_column_bet();
        end;
    2: click_second_dozen_bet();
    3: click_third_dozen_bet();
    else click_straight_up_0();
end;


VI.
Logical Operators

The logical operators are expressions which return a false or true result over a conditional expression. They are also used in assignments (an example of this would be shown later). Such  operators consist of simple logical operators, such as 'Not' or 'And'. They should be used between two conditional expressions ; for example:

If (x = 0) AND (a = 2) then...

note: When combining two Boolean expressions using relational and Boolean operators, be careful to use parentheses.

There are three types of logical operators, each of which are concerned with conditional expressions. These are:
    AND - conjunction
    OR - disjunction
    NOT - negation

All of these logical operators have a different effect on the conditional expressions. Let's see what each of the logical operator does two (or more) conditional expressions...

NOT is a unary operator it is applied to only one value and inverts it:
    * not true = false
    * not false = true

AND return TRUE only if both values are TRUE:
    * TRUE and FALSE = FALSE
    * TRUE and TRUE = TRUE

OR return TRUE if at least one value is TRUE:
    * TRUE or TRUE = TRUE
    * TRUE or FALSE = TRUE
    * FALSE or TRUE = TRUE
    * FALSE or FALSE = FALSE

Examples:
if (landed_number>=1)and(landed_number<=12) then print('Number is from Dozen1');

if not((landed_number>=1)and(landed_number<=12)) then print('Number is not from Dozen1');

if (landed_number<=12)or(landed_number>=25) then print('Number is from Dozen1 or from Dozen3 or it is Zero');

if ((landed_number<=12)or(landed_number>=25))and(landed_number<>0) then print('Number is from Dozen1 or from Dozen3, and it is not Zero.');

if ((landed_number<=12)or(landed_number>=25))and(landed_number<>0)
  then print('Number is from Dozen1 or from Dozen3, and it is not Zero.')
  else print('Number is from Dozen2.');


VII.
The Boolean Expressions


The boolean expressions are the terms ' true ' and ' false '. These are simply similar to 1's (for true) and 0's(for false). They describe an expression whether it is false or true . The variable types over boolean expressions is the 'boolean' type.

Example: will bet on dozen2 and on dozen3 if landed_number is from dozen1.


var isDozen1, landed_number;
begin
    set_roulette_window_name('European Roulette - onlineCasino.com');
    click_spin();
    landed_number:=get_last_number();
    isDozen1:=False;//any variable must be initialize first
    if ((landed_number>=1)and(landed_number<=12)) then isDozen1:=True;
    if isDozen1 then begin
      click_chip2();
      click_second_dozen_bet();
      click_third_dozen_bet();
      click_spin();
      print('We have bet chip2 on dozen2 and on dozen3');
      print('Landed number is');
      print(get_last_number());
    end else print('Landed number is not Dozen1');
end;
 
Copyright © 2007-2011, All rights reserved to Money Maker Machine