[email protected] Posted March 26, 2014 Share Posted March 26, 2014 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_10001: wait 0 msif0AB0: key_pressed 8//-----------------key = Backspace004D: jump_if_false @slow_10A1E: dump_screen 1 // Action0002: jump @slow_1 IF...THEN...ELSE..END statement: High Level Syntax: ifPlayer.Defined($PLAYER_CHAR)thenActor.DestroyInstantly($PLAYER_ACTOR)elsePlayer.Build($PLAYER_CHAR)end Will be same as: Low level: ifPlayer.Defined($PLAYER_CHAR)jf @LABELActor.DestroyInstantly($PLAYER_ACTOR)jump @LABEL2:LABELPlayer.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_003A4: name_thread 'SLW' :slow_10001: wait 0 msif0AB0: key_pressed 8//-----------------key = Backspace004D: jump_if_false @slow_1015D: set_gamespeed .30001: wait 50 ms :slow_20001: wait 0 msif0AB0: key_pressed 8//-----------------key = Backspace004D: jump_if_false @slow_2015D: set_gamespeed 1.00001: wait 1000 ms0002: 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 endend 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 commandifkey_pressed 8jf continue // uses instead of a label // *****************************// //Use of continue as separate command ifnot key_pressed 8thencontinue // 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 [email protected] = 354164 to 354188&0([email protected],1i) = 16843009end 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 iterationRepeat .. 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.0end 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.. Link to comment Share on other sites More sharing options...
DK22Pac Posted March 26, 2014 Share Posted March 26, 2014 That is not advanced scripting, that's SB syntax. Zintro and RyanDri3957V 2 Link to comment Share on other sites More sharing options...
Gyaviste Posted December 26, 2014 Share Posted December 26, 2014 How to switch to high level syntax? Link to comment Share on other sites More sharing options...
ZAZ Posted December 26, 2014 Share Posted December 26, 2014 no need for any switch, just use it like [email protected] showed RyanDri3957V 1 CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...