Position number x, number y, number zWhat this tells us is that the Position command has 3 parameters: x, y, and z. These parameters also happen to all be numbers .
Moves the currently selected item to the specified position in meters.
Position 0, 0, 0 ; Moves item to position (0, 0, 0).
int : integers. Examples would be: 1, 2, -23, 14, 0.
Position 0 1.5 -2 ; Move selected item to (0, 1.5, -2)We can also write it like this with commas (encouraged):
Position 0, 1.5, -2 ; Move selected item to (0, 1.5, -2)Try selecting any object in layout, fire up skelescript preview, and run the the line of code above by typing it and pressing execute (F5). If you typed it correctly, you should see the selected object move to the newly specified position.
Comments can be a very important part of your code. You can help separate and identify groups of code, explain what's happening, etc. Beginners can benefit a lot by writing English translations of what each line of code is doing as in the above example with the Position command.; This is how you write a comment in skelescripts. ; The following is an example of how you can write comments ; immediately after a command on the same line. Position 0, 0, 0 ; Move an item to the origin
msg any message
Displays the specified message to the screen in a message box.
; displays 'hello world!' to the screen. msg "hello world!" ; displays the coordinates of the currently selected item to the screen. msg ("Position: (" & world_x & ", " & world_y & ", " & world_z & ")" )
The interpreter would be very confused, because it would see this line as containing two arguments, 'hello' and 'world!', even though the msg command takes only one argument. Because strings can contain spaces as well as other characters which can potentially lead to ambiguities in the script, strings are marked with quotes to distinguish them, like this:msg hello world!
On the other hand, LS Commander does not use quotes to distinguish strings, and because Skelescripts are designed with compatibility in mind, it provides the option to write strings without using quotes. To be able to do this, you must set the ls_compatible property to true (you will find out how to do this later).msg "hello world!"
- turns a positive value into a negative value. This only applies for numeric types.
& concatenates both operands into a single string. 1 & 2 evaluates to the string, "12". "Hello" & 123 evaluates to the string, "Hello123".
Position 1 + 1 2 3It's difficult for the interpreter to figure out whether this line has 5 arguments or 3, especially since the + itself might be a perfectly valid argument when ls_compatible mode is on (more on this later). As a result, to group an expression together as a single argument, you must enclose it in parentheses like this:
Position (1 + 1) 2 3When writing expressions for arguments of functions and properties (see below) where commas are required, enclosing the expression in parentheses is not required.
string name (item_id item = selected)The name command takes one argument: an item ID specifying which item's name you want to retrieve. Before we move on, let's take a look at one other function, the selected function:
Returns the name of the specified item (if no item is specified, the first selected item will be used by default).
item_id selected (int index = 0)This function takes one argument: an index specifying which selected item you want to retrieve. The index starts from 0 for the first selected item and advances to 1 for the second selected item, 2 for the third selected item, and so forth. Combining what we've learned about the selected command and the name command, let's write a command that displays the name of the second item in the selection:
Returns the item ID of one of the selected item based on the index. The index starts at 0, meaning that the first element has an index 0, the second has an index of 1, and so forth. If no index is supplied, the ID of the first selected item will be returned. The function returns null_item if there is no selected item for the specified index.
; Displays the name of the first selected item. msg name(selected) ; This also displays the name of the first selected item. msg name(selected(0) ) ; This displays the name of the third selected item. msg name(selected(2) )
The first thing that's evaluated in this line of code is the call to selected. The integer, 1, is passed to the selected function as an argument specifying which item we want to retrieve. The index of 1 indicates that we want the second selected item. The expression, selected(1), ends up being evaluated to the item ID of the second selected item, which is then used as the first argument to the name function. The name function in turn returns the name of that item (let's say the name was "foo" for example). The string "foo", which is returned from the name function, is then used as an argument to the msg function. The final effect is that the string, "foo" will be displayed in a message box, showing us the name of the second selected item.; We'll use the msg command we learned earlier to display a message ; with the second selected item's name. msg name(selected(1) )
It will display the name of the first selected item because an index of 0 will be used by default. When you aren't specifying any arguments with a function call, you can omit the parentheses completely like this:msg name(selected() )
This is the same as writing this:msg name(selected)
Likewise, the name function's item argument has a default value of selected , meaning that the selected function's return value will be used as the default value if no argument is specified. This means that if I write:msg name(selected(0) )
It will display the name of the first selected item, and is the same as writing (because of the item's default value of selected for the name function):msg name
Which is the same as writing (because of the index's default value of 0 for the selected function):msg name(selected)
To beginners, this might be a bit confusing at first. The best way to learn is to look at various code samples and practice to see the difference for yourself. Just remember that any parameter specified in the command reference followed by an equal sign and a value is an optional parameter which does not have to receive an argument.msg name(selected(0) )
number add (number lhs, ~number remaining)The add function returns the sum of two or more numbers. The tilde right before the data type (number) of the second parameter, remaining , is very important. It indicates that the remaining parameter is a remaining arguments collection . Whenever you see these in the reference guide, it means that the parameter can receive 0 or more arguments (virtually up to an infinite number of them). So, with regards to the add function's syntax, this means that the function can take 1 to an infinite number of arguments, because the first one, lhs , is required, while the second one, remaining , is a remaining arguments collection which can have 0 or more arguments passed to it.
While it's syntactically correct to have only 1 argument for a call to a function like add , it is not always logically correct . Not all functions allow an empty remaining arguments collection, and the add function is no exception. It would be pointless to find the sum of only one number, since there's nothing else to add up. Therefore, while it's syntactically correct to write code like this:msg add(1, 2) ; displays 3 msg add(1, 2, 3) ; displays 6 msg add(1, 2, 3, 4) ; displays 10 msg add(1, 2, 3, 4, 5) ; displays 15 msg add(1, 2, 3, 4, 5, 6) ; displays 21 ; You can keep going like this forever (or at least until your computer runs ; out of memory).
You will still receive an error when running the code because the add function will check the remaining arguments collection to make sure that there is at least 1 argument passed to it.msg add(1)
item_id create_null_at (item_id item, string name, number add_x = 0, number add_y = 0, number add_z = 0)This is a function that takes 2 to 5 arguments and returns an item ID. The first two arguments are required since the parameters are not optional (they do not have default values). The first argument is an item ID, meaning it refers to a specific item. The second argument is a string, so we can pass arguments like "foo" or "hello". The remaining 3 parameters are optional number parameters which have a default value of 0, meaning that if we choose to only pass 2 arguments like this:
It would be the same as writing:msg create_null_at(selected(0), "foo")
Which would also be the same as writing (remember that the selected function's index optionally defaults to 0):msg create_null_at(selected(0), "foo", 0, 0, 0)
Which would also be the same as writing:msg create_null_at(selected, "foo", 0, 0, 0)
And so forth. All of the above lines of code will create a null at the first selected item with the name of "foo". Since the position we specified (or left by default) is (0, 0, 0), this means that the item is not displaced at all from the original position (which is the position of the selected item). Further, we wrote the function as an argument to the msg command, meaning that once the null is created, its ID will be returned by the create_null_at function to be displayed to the screen in a message box.msg create_null_at(selected, "foo", 0)
create_goal bool full_time = true, string null_name = concat(name, "_goal"), number add_x = 0, number add_y = 0, number add_z = 0All parameters of this command have default values, meaning that this command can take 0 to 5 arguments. Here are some valid examples:
I'll now make up a new command which we can analyze.create_goal create_goal true create_goal false create_goal false, "foo" create_goal false, "bar", 1.5 create_goal false, "baz", 1.5, 2.0 create_goal false, "qux", 1.5, 2.0, 1.2345 create_goal 1, "quux", 1.5, 2.0, 1.2345 create_goal 123, "quuux", 1.5, 2.0, 1.2345 ; same as previous line create_goal true, "quuuux", 1.5, 2.0, 1.2345 ; same as previous two lines
foo bool arg1, number arg2, string arg3 = "hello", ~bool remaining_argumentsThis command takes 2 to an infinite number of arguments. The first argument is required and must evaluate to a boolean value (true or false). The second argument is also required and must evaluate to a real number. The third argument is optional and must evaluate to a string. The remaining arguments are also optional and must be a boolean value. Here are some examples of syntactically correct command calls:
Remember that a non-zero value is regarded as true while a non-zero value is regarded as false .foo true, 123 foo false, 456, "qux" foo false, 789, "quux", true foo false, 789, "quuux", true, false foo 1, 789, "quuuux", true, false, false foo 0, 789, "quuuuux", true, false, false, 1 foo 0, 789, "quuuuuux", true, false, false, 1, 0, 0, true, false, true
bool auto_confirmUnlike any of the procedures (refers to commands, functions, and properties) we've seen so far, these properties take no arguments at all.
bool auto_key
bool parent_in_place
These properties should be fairly obvious by their name. They allow you to change boolean (true/false) layout states like whether autokey is on or off.
Like with any function or property that doesn't take or require arguments, you can omit the parentheses altogether and simply write:; displays true (a non-zero value) if auto key is on, false (0) ; if auto key is off. msg auto_key()
Working with readable properties is no different from functions, so you should have no problem working with them at this point.msg auto_key
bool auto_confirmThe example code provided in the reference should already give you a good idea of how to work with writable properties. You simply write set followed by the property name and any arguments you want to pass in parentheses (using the same syntax as a function call) followed by the value you want to assign to the property.
bool auto_key
bool parent_in_place
These properties should be fairly obvious by their name. They allow you to change boolean (true/false) layout states like whether autokey is on or off.
set auto_key, true ; turn on autokey. set parent_in_place, false ; turn off parent in place.
set property_name(arg1, arg2, etc), new_value The value you assign to a property must be of the appropriate data type. Looking at the writable properties above, all of these properties are of the bool (boolean) type. This means that you can assign either true (non-zero value) or false (0).
int pitch_controller (item_id item = selected)These writable properties have one optional argument which can specify an existing item ID. They must be assigned values of the int (integer) type. Here are some valid examples of their usage:
int heading_controller (item_id item = selected)
int bank_controller (item_id item = selected)
Sets the specified item's controller for the appropriate channel (heading, pitch, or bank). The valid values are: controller_keyframes, controller_align_to_path, controller_targeting, and controller_ik.
; The following code selects the current skelescript bone and sets ; its pitch controller to inverse kinematics. select me set pitch_controller, controller_ik
While we can specify integers like 2 and so forth, the integers have a special meaning in this case. Different integers refer to different controller types. To prevent you from having to memorize the number for each controller, a set of named constants have been pre-defined for you:set pitch_controller(selected(0) ), 2 ; same as previous line because of default value for selected set pitch_controller(selected), 2 ; same as previous line because of default value for pitch_controller set pitch_controller, 2
any controller_keyframes = 0These have the purpose of associating a name to a value. The true /false values we've been using are also examples of named constants. The named constant, true , simply evaluates to 1 (remember that any non-zero is regarded by the interpreter as true). The named constant, false , evaluates to 0. While you can just write 1 (or any non-zero value) or 0 in their place, it is more intuitive to read and write 'true' and 'false' instead.
any controller_targeting = 1
any controller_align_to_path = 2
any controller_ik = 3
The above constants represent each of the different types of controllers that can control the orientation of an item.
Named constants like these help make your code more readable and manageable by using words in place of numbers.; instead of writing this to set the pitch controller to IK: set pitch_controller, 3 ; we can write this instead: set pitch_controller, controller_ik