Quantcast

Jump to content

» «
Photo

CLEO Advanced Script tutorial

3 replies to this topic
T@zz
  • T@zz

    Player Hater

  • Members
  • Joined: 23 Mar 2014
  • India

#1

Posted 26 March 2014 - 09:39 AM

This is CLEO Advanced script tutorial. It will be useful to beginners as well as intermediates and advanced modders. High Level scripting is not so difficult as you might think on the other hand it's a bit easier if you grasp the concept clearly. I know there is a great tutorial about CLEO Scripting by ZAZ but it doesn't include clearly the concepts like high level scripting, using high level structures, call scm method, memory scripting etc. But to understand the tutorial fully you do need to know the basic of scripting.

Now without wasting time let’s start our tutorial.

 

HIGH LEVEL STRUCTURES

Conditional statements:  Sanny Builder supports high level conditional statements like:

IF...THEN...END statement:

High Level syntax:

if
                key_pressed 8                      // Condition
           then
                0A1E: dump_screen 1  // Action
                end

In Low Level:

:slow_1
0001: wait  0 ms
if
0AB0:   key_pressed 8//-----------------key = Backspace
004D: jump_if_false @slow_1
0A1E: dump_screen 1  // Action
0002: jump @slow_1

IF...THEN...ELSE..END statement:

High Level Syntax:

if
Player.Defined($PLAYER_CHAR)
then
Actor.DestroyInstantly($PLAYER_ACTOR)
else
Player.Build($PLAYER_CHAR)
end

 

Will be same as:

Low level:

if
Player.Defined($PLAYER_CHAR)
jf @LABEL
Actor.DestroyInstantly($PLAYER_ACTOR)
jump @LABEL2
:LABEL
Player.Build($PLAYER_CHAR)
:LABEL2

 

Now let’s work with it by using the above script in a CLEO Script:

(In low level script)

{$CLEO}
 
:slow_0
03A4: name_thread 'SLW'
 
:slow_1
0001: wait  0 ms
if
0AB0:   key_pressed 8//-----------------key = Backspace
004D: jump_if_false @slow_1
015D: set_gamespeed  .3
0001: wait  50 ms
 
:slow_2
0001: wait  0 ms
if
0AB0:   key_pressed 8//-----------------key = Backspace
004D: jump_if_false @slow_2
015D: set_gamespeed  1.0
0001: wait  1000 ms
0002: jump @slow_1 

Will be same as:

{$CLEO}
0000:
while true   
wait 0
    if
        key_pressed 8
    then
        015D: set_gamespeed 0.3
        wait 50
    end
   
    if
        key_pressed 8
    then
    015D: set_gamespeed 1.0
    wait 1000
    end
end

 

Try to look at the code you will easily understand the High level script easily than the low level.

You might have come across the while structure, so let’s know workaround with it.

WHILE...END Structure

Loop WHILE is working until the condition returns True. The condition is evaluated before the loop iterations. Hence, if the condition is false, the statement sequence is never executed.

The general syntax is as follows:

WHILE <condition>
...
END

Operator WHILE may accept the logic constants True and False:

While True..End - loop executes infinitely until the loop stopped by command Break.

While False .. End - loop is ignored by the compiler.

 

Using Continue & Break commands:

If you want to skip the current iteration and proceed to the next, use the command Continue. You can use it as (jf continue) or as only continue.

Ex:

// Use of jf continue command
if
key_pressed 8
jf continue // uses instead of a label
 
// *****************************//
 
//Use of continue as separate command
 
if
not key_pressed 8
then
continue // uses as a jump to the next iteration

The useful command, Break, causes the flow of loop to exit.  It can be used both as a separate command or parameter (jf break).It also stops the while true...end loop.

For...End loop:

General Syntax:

 

FOR <counter> = <initial value> TO/DOWNTO <final value> step <int> = 1
...
END

<counter> - variable that is used as the loop iterations (repeats) counter.

<initial value> - starting value of the counter (any value including the model identifiers).

TO/DOWNTO - at TO the counter is increased, at DOWNTO - is decreased.

<final value> - - final value of the loop when finished.
(any value including the model identifiers).

<step> - value of an increment or reduction of the counter after iteration.
(optional). By default its value is equal to 1.

Basically this is quite old command & not pretty usable still you can use it for many purposes like:

Clearing map fog:

{$CLEO}
for 0@ = 354164 to 354188
&0(0@,1i) = 16843009
end

Can be used for Checking all peds, weapons etc..I just lack much ideas with for loop.

Anyways let’s move to next part.

REPEAT..UNTIL statement:

This loop continues until the condition is returned either true or false depending upon the logic operator used.

Repeat .. Until True - loop has the only iteration
Repeat .. Until False - loop executes infinitely until it's stopped by Break.

 

KEYWORDS:

Sanny Builder provides you some useful keywords which can be used instead of the opcodes.

For example:

wait 0 is same as 00001: wait 0

create_thread @NONAME_01 is same as 0004: create_thread @NONAME_01 

By pressing CTRL + SPACE you can view the list of all keywords.

 

VAR..END Structure:

VAR..END contruct allows to declare variables and their types for advanced use. You can use them as special CLEO Global variables as using simple Global variables will create crashes or random bugs.

Example:

var  
$TIME : Int   // Declare the data type of the variable as Int, Float.
$SCORE : Int  //Same as above ?
end
$TIME = 180000                        //Same as below ?
$SCORE = 0                       //Using the variable in the script.
end_custom_thread                    //same as 004E:

A code snippet from my RC Mission mod.

 

Also you can set an initial value for the variable when declaring it.
For this purpose write symbol = and after that, the initial value
:

var
$fVar: float = 1.0
end

 

Variable $fVar will be remembered as Float and also the compiler will write an opcode in the SCM.

0005: $fVar = 1.0 

Initialization is allowed for the variables only.

 

 

More things would be added soon.

TO DO LIST:

  • call_scm_functions

  • hex..end structures

  • Memory scripting

  • Arrays (Advanced way)

  • etc..

 


DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]

#2

Posted 26 March 2014 - 01:54 PM

That is not advanced scripting, that's SB syntax.

Gyaviste
  • Gyaviste

    Player Hater

  • New Members
  • Joined: 26 Dec 2014
  • Ukraine

#3

Posted 26 December 2014 - 09:23 AM

How to switch to high level syntax?


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union

#4

Posted 26 December 2014 - 02:01 PM

no need for any switch, just use it like T@zz showed




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users