From fddd0a68178da57e0416722ee7c003eab7167ac4 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 13 May 2014 21:12:15 +0200 Subject: Partial cleanup of script_commands.txt - Updated examples to a more modern syntax - Corrected examples using the wrong case for script commands (fixes bugreport:8192 thanks to jaBote) http://hercules.ws/board/tracker/issue-8192-camelcase-in-scripting-documentation/ - Reworded or rewritten some misleading/no longer correct notes to match the current script engine behavior. - Marked some commands as deprecated and suggested alternatives, to discourage their use in new scripts (set, goto, jump_zero, menu) - Changed use of temporary character variables into scope variables in examples, where appropriate. Signed-off-by: Haru --- doc/script_commands.txt | 1077 +++++++++++++++++++++++------------------------ 1 file changed, 529 insertions(+), 548 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 31574d0a2..638c959cb 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -478,15 +478,15 @@ nothing - A permanent variable attached to the character, the default .variables which are accessible from inside the function, however 'getvariableofnpc' does NOT work on function objects. ".@" - A scope variable. - They are unique to the instance and scope. Each instance has - its own scope that ends when the script ends. Calling a - function with callsub/callfunc starts a new scope, returning - from the function ends it. When a scope ends, it's variables - are converted to values ('return .@var;' returns a value, not a - reference). + They are unique to the character, script and scope. Each script + execution has its own scope that ends when the script ends. + Calling a function with callsub/callfunc starts a new scope, + returning from the function ends it. When a scope ends, its + variables are converted to values ('return .@var;' returns a + value, not a reference). "'" - An instance variable. These are used with the instancing system, and are unique to - each party's instance. + each instance. "#" - A permanent local account variable. "##" - A permanent global account variable stored by the login server. The only difference you will note from normal # variables is @@ -512,6 +512,8 @@ $@name$ - temporary global string variable .name$ - NPC string variable .@name - scope integer variable .@name$ - scope string variable + 'name - instance integer variable + 'name$ - instance string variable #name - permanent local account integer variable #name$ - permanent local account string variable ##name - permanent global account integer variable @@ -579,23 +581,24 @@ Variables can be accessed and assigned values directly without the use of the built-in 'set' function. This means that variables can be accessed and modified much like other programming languages. - @x = 100; - @x = @y = 100; + .@x = 100; + .@x = .@y = 100; Support for modifying variable values using 'set' is still supported (and required to exist for this method to work) so previous scripts will -continue working. +continue working. Its usage, though, is deprecated, and it should never be +used in new scripts unless there are special reasons to do so. When assigning values, all operator methods are supported which exist in the below 'Operators' section. For instance: - @x += 100; - @x -= 100; - @x *= 2; - @x /= 2; - @x %= 5; - @x >>= 2; - @x <<= 2; + .@x += 100; + .@x -= 100; + .@x *= 2; + .@x /= 2; + .@x %= 5; + .@x >>= 2; + .@x <<= 2; Will all work. For more information on available operators, see the Operators section described below. All operators listed there may be @@ -605,22 +608,22 @@ action as required. Increment and decrement operators are also provided, for your convenience. Pre-increment and pre-decrement operators: - ++@x; // same as @x = @x + 1 - --@x; // same as @x = @x - 1 + ++.@x; // same as .@x = .@x + 1 + --.@x; // same as .@x = .@x - 1 Post-increment and post-decrement operators: - @x++; // similar to @x = @x + 1 - @x--; // similar to @x = @x - 1 + .@x++; // similar to .@x = .@x + 1 + .@x--; // similar to .@x = .@x - 1 The difference between pre- and post- increment/decrement operators is that, when used in an expression, the pre- ones will be executed before evaluating the expression, while the post- ones will be executed after. For example: - @x = 1; - @y = ++@x; // After this line is executed, both @y and @x will be 2 - @x = 1; - @y = @x++; // After this line is executed, @y will be 1, @x will be 2 + .@x = 1; + .@y = ++.@x; // After this line is executed, both .@y and .@x will be 2 + .@x = 1; + .@y = .@x++; // After this line is executed, .@y will be 1, .@x will be 2 Note: The pre-increment/pre-decrement operators are, by design, faster (or at least not slower) than their respective post- equivalent. @@ -634,8 +637,10 @@ Note: Strings ------- -To include symbol '"' in a string you should use prefix '\"'. +Strings are enclosed in "double quotes". To include the literal double +quote symbol (") in a string you need to escape it with a blackslash: + .@string$ = "This string contains some \"double quote\" symbols"; Arrays ------ @@ -646,69 +651,36 @@ array with an 'array index', a number of a variable in that array: [] +All variable types can be used as arrays. + Variables stored in this way, inside an array, are also called 'array elements'. Arrays are specifically useful for storing a set of similar -data (like several item IDs for example) and then looping through it. You +data (like several item IDs for example) and then looping through it. You can address any array variable as if it was a normal variable: - set @arrayofnumbers[0],1; + .@arrayofnumbers[0] = 1; -You can also do sneaky things like using a variable (or an expression, or -even a value from an another array) to get at an array value: +You can use a variable (or an expression, or even a value from an another +array) as array index: - set @x,100; - set @arrayofnumbers[@x],10; + .@x = 100; + .@arrayofnumbers[.@x] = 10; -This will make @arrayofnumbers[100] equal to 10. +This will make .@arrayofnumbers[100] equal to 10. -Notice that index numbering always starts with 0. Arrays can hold over -2 billion variables. +Index numbering always starts with 0 and arrays can hold over 2 billion +variables. As such, the (guaranteed) allowed values for indices are in the +range 0 ~ 2147483647. -And array indexes probably can't be negative. Nobody tested what happens -when you try to get a negatively numbered variable from an array, but it's -not going to be pretty. :) +If the array index is omitted, it defaults to zero. Writing +.@arrayofnumbers is perfectly equivalent to writing .@arrayofnumbers[0]. Arrays can naturally store strings: -@menulines$[0] is the 0th element of the @menulines$ array of strings. +.@menulines$[0] is the 0th element of the .@menulines$ array of strings. Notice the '$', normally denoting a string variable, before the square brackets that denotes an array index. -Resume of the allowed variable and array scopes ------- -- --- ------- -------- --- ----- ------ - -+==========+======+=======+ -|VarType | Norm | Array | -+==========+======+=======+ -|$Str$ | OK! | OK! | -+----------+------+-------+ -|$@Str$ | OK! | OK! | -+----------+------+-------+ -|@Str$ | OK! | OK! | -+----------+------+-------+ -|#Str$ | OK! | FAIL! | -+----------+------+-------+ -|Str$ | OK! | FAIL! | -+----------+------+-------+ -|$Int | OK! | OK! | -+----------+------+-------+ -|$@Int | OK! | OK! | -+----------+------+-------+ -|@Int | OK! | OK! | -+----------+------+-------+ -|#Int | OK! | FAIL! | -+----------+------+-------+ -|Int | OK! | FAIL! | -+----------+------+-------+ -|.Str$ | OK! | OK! | -+----------+------+-------+ -|.Int | OK! | OK! | -+----------+------+-------+ -|.@Str$ | OK! | OK! | -+----------+------+-------+ -|.@Int | OK! | OK! | -+----------+------+-------+ - Variable References ------------------- @@ -760,7 +732,7 @@ Examples: 1==1 is True. 1<2 is True while 1>2 is False. - @x>2 is True if @x is equal to 3. But it isn't true if @x is 2. + .@x>2 is True if .@x is equal to 3. But it isn't true if .@x is 2. Only '==', '!=', '~=' and '~!' have been tested for comparing strings. Since there's no way to code a seriously complex data structure in this language, @@ -785,10 +757,10 @@ Logical bitwise operators work only on numbers, and they are the following: In the other hand, Right shift moves the binary 1(s) of a number n positions to the right, which is the same as dividing by 2, n times. Example: - set b,2; - set a, b << 3; + b = 2; + a = b << 3; mes a; - set a, a >> 2; + a = a >> 2; mes a; The first mes command would display 16, which is the same as: 2 x (2 x 2 x 2) = 16. @@ -823,12 +795,12 @@ Logical bitwise operators work only on numbers, and they are the following: arguments, so in the example 1010 & 0010, only the 2^1 bit is active (1) in both. Resulting in the bit 0010, which is 2. - Basic example of creating and using a bit-mask: - set @options,2|4|16; // (note: this is the same as 2+4+16, or 22) - if (@options & 1) mes "Option 1 is activated"; - if (@options & 2) mes "Option 2 is activated"; - if (@options & 4) mes "Option 3 is activated"; - if (@options & 8) mes "Option 4 is activated"; - if (@options & 16) mes "Options 5 is activated"; + .@options = 2|4|16; // (note: this is the same as 2+4+16, or 22) + if (.@options & 1) mes "Option 1 is activated"; + if (.@options & 2) mes "Option 2 is activated"; + if (.@options & 4) mes "Option 3 is activated"; + if (.@options & 8) mes "Option 4 is activated"; + if (.@options & 16) mes "Option 5 is activated"; This would return the messages about option 2, 3 and 5 being shown (since we've set the 2,4 and 16 bit to 1). ^ - Xor. @@ -840,21 +812,19 @@ Logical bitwise operators work only on numbers, and they are the following: Example: - First let's set the quests that are currently in progress: - set inProgress,1|8|16; // quest 1,8 and 16 are in progress + inProgress = 1|8|16; // quest 1,8 and 16 are in progress - After playing for a bit, the player starts another quest: if( inProgress&2 == 0 ){ - // this will set the bit for quest 2 (inProgress has that bit - // set to 0) - set inProgress,inProgress^2; + // this will set the bit for quest 2 (inProgress has that bit set to 0) + inProgress = inProgress^2; mes "Quest 2: find a newbie and be helpful to him for an hour."; close; } - After spending some time reading info on Xor's, the player finally completes quest 1: - if( inProgress&1 && isComplete ){ - // this will unset the bit for quest 1 (inProgress has that - // bit set to 1) - set inProgress,inProgress^1; + if( inProgress&1 && isComplete ) { + // this will unset the bit for quest 1 (inProgress has that bit set to 1) + inProgress = inProgress^1; mes "Quest 1 complete!! You unlocked the secrets of the Xor dynasty, use them wisely."; close; } @@ -867,7 +837,7 @@ operator, and are the following: it will become negative and vice versa. Example: - set .@myvar,10; + .@myvar = 10; mes "Negative 10 is "+(-.@myvar); ! - Logical Not. @@ -875,8 +845,7 @@ operator, and are the following: and false will become true. Example: - if(!callfunc("F_dosomething")) - { + if(!callfunc("F_dosomething")) { mes "Doing something failed."; close; } @@ -888,8 +857,8 @@ operator, and are the following: Example: - Ensure, that quest 2 is disabled, while keeping all other active, if they are. - set inProgress,inProgress&(~2); - // same as set inProgress,inProgress&0xfffffffd + inProgress = inProgress&(~2); + // same as set inProgress,inProgress&0xfffffffd Ternary operators take three expressions (numbers, strings or boolean), and are the following: @@ -1296,28 +1265,25 @@ Don't expect things to run smoothly if you don't make your scripts 'end'. This command will stop the execution for this particular script. It is required for any script not using 'mes'. - if (BaseLevel<=10) goto L_Lvl10; - if (BaseLevel<=20) goto L_Lvl20; - if (BaseLevel<=30) goto L_Lvl30; - if (BaseLevel<=40) goto L_Lvl40; - if (BaseLevel<=50) goto L_Lvl50; - if (BaseLevel<=60) goto L_Lvl60; - if (BaseLevel<=70) goto L_Lvl70; - L_Lvl10: + if (BaseLevel <= 10) { npctalk "Look at that you are still a n00b"; end; - L_Lvl20: + } + if (BaseLevel <= 20) { npctalk "Look at that you are getting better, but still a n00b"; end; - L_Lvl30: + } + if (BaseLevel <= 30) { npctalk "Look at that you are getting there, you are almost 2nd profession now right???"; end; - L_Lvl40: + } + if (BaseLevel <= 40) { npctalk "Look at that you are almost 2nd profession"; end; + } -Without the use if 'end' it would travel through the labels until the end -of the script. If you were lvl 10 or less, you would see all the speech +Without the use of 'end' it would travel through the ifs until the end +of the script. If you were lvl 10 or less, you would see all the speech lines, the use of 'end' stops this, and ends the script. --------------------------------------- @@ -1330,19 +1296,9 @@ in. This isn't the only way to set a variable directly: you can set them much like any other programming language as stated before (refer to the 'Assigning variables' section). -This is the most basic script command and is used a lot whenever you try -to do anything more advanced than just printing text into a message box. - - set @x,100; - -will make @x equal 100. - - set @x,1+5/8+9; - -will compute 1+5/8+9 (which is, surprisingly, 10 - remember, all numbers -are integer in this language) and make @x equal to it. - -Returns the variable reference. +This command is deprecated and it shouldn't be used in new scripts, except +some special cases (mostly, set getvariableofnpc). Use direct value +assignment instead. --------------------------------------- @@ -1374,8 +1330,8 @@ This can also be used to set an array dynamically: Examples: - set getd("$varRefence"), 1; - set @i, getd("$" + "pikachu"); + mes "The value of $varReference is: " + getd("$varRefence"); + set .@i, getd("$" + "pikachu"); --------------------------------------- @@ -1392,10 +1348,10 @@ Examples: //This will set the .v variable to the value of the TargetNPC's .var //variable. - set .v,getvariableofnpc(.var,"TargetNPC"); + .v = getvariableofnpc(.var,"TargetNPC"); //This will set the .var variable of TargetNPC to 1. - set getvariableofnpc(.var,"TargetNPC"),1; + set getvariableofnpc(.var,"TargetNPC"), 1; Note: even though function objects can have .variables, getvariableofnpc will not work on them. @@ -1426,6 +1382,10 @@ Depending on what the player picks from the menu, the script execution will continue from the corresponding label. It's string-label pairs, not label-string. +This command is deprecated and it should not be used in new scripts, as it +is likely to be removed at a later time. Please consider using select() or +prompt() instead. + Options can be grouped together, separated by the character ':'. menu "A:B",L_Wrong,"C",L_Right; @@ -1474,47 +1434,46 @@ populate it with the strings that should go into the menu at this execution, making sure not to leave any gaps. Normally, you do it with a loop and an extra counter, like this: - setarray @possiblemenuitems$[0],; - set @j,0; // That's the menu lines counter. + setarray .@possiblemenuitems$[0],; + .@j = 0; // That's the menu lines counter. // We loop through the list of possible menu items. - // @i is our loop counter. - for( set @i,0; @i) { // We record the option into the list of options actually - // available. + // available. - set @menulist$[@j],@possiblemenuitems$[@i]; + set .@menulist$[.@j],.@possiblemenuitems$[.@i]; // We just copied the string, we do need it's number for later // though, so we record it as well. - set @menureference[@j],@i; + set .@menureference[.@j],.@i; // Since we've just added a menu item into the list, we - // increment the menu lines counter. + // increment the menu lines counter. - set @j,@j+1; + ++.@j; } // We go on to the next possible menu item. } -This will create you an array @menulist$ which contains the text of all +This will create you an array .@menulist$ which contains the text of all items that should actually go into the menu based on your condition, and -an array @menureference, which contains their numbers in the list of +an array .@menureference, which contains their numbers in the list of possible menu items. Remember, arrays start with 0. There's less of them than the possible menu items you've defined, but the menu command can handle the empty lines - only if they are last in the list, and if it's made this way, they are. Now comes a dirty trick: // X is whatever the most menu items you expect to handle. - menu @menulist$[0],-,@menulist$[1],-,....@menulist$[],-; + menu .@menulist$[0],-,.@menulist$[1],-,...,.@menulist$[],-; This calls up a menu of all your items. Since you didn't copy some of the possible menu items into the list, it's end is empty and so no menu items @@ -1530,19 +1489,19 @@ starting with 1 for the first option. You know now which option the user picked and which number in your real list of possible menu items it translated to: - mes "You selected "+@possiblemenuitems$[@menureference[@menu-1]]+"!"; + mes "You selected "+.@possiblemenuitems$[.@menureference[@menu-1]]+"!"; @menu is the number of option the user picked. @menu-1 is the array index for the list of actually used menu items that we made. -@menureference[@menu-1] is the number of the item in the array of possible +.@menureference[@menu-1] is the number of the item in the array of possible menu items that we've saved just for this purpose. -And @possiblemenuitems$[@menureference[@menu-1]] is the string that we +And .@possiblemenuitems$[.@menureference[@menu-1]] is the string that we used to display the menu line the user picked. (Yes, it's a handful, but it works.) -You can set up a bunch of 'if (@menureference[@menu-1]==X) goto Y' +You can set up a bunch of 'if (.@menureference[@menu-1]==X) goto Y' statements to route your execution based on the line selected and still generate a different menu every time, which is handy when you want to, for example, make users select items in any specific order before proceeding, @@ -1555,7 +1514,7 @@ doesn't use @menu, probably since that wasn't documented anywhere. See also 'select', which is probably better in this particular case. Instead of menu, you could use 'select' like this: - set @dummy,select(@menulist$[0],@menulist$[1],....@menulist$[]); + .@dummy = select(.@menulist$[0],.@menulist$[1],...,.@menulist$[]); For the purposes of the technique described above these two statements are perfectly equivalent. @@ -1565,13 +1524,13 @@ perfectly equivalent. *select("