3 August 2023
31 July 2019
selection
optional parameter.20 May 2017
updatescript (Commands) | |
---|---|
Type | Corrade progressive command |
Command | updatescript |
Description | The updatescript command is used to update or create a new script inside either Corrade's inventory or inside a primitive's (task) inventory. |
Permissions | inventory , interact |
Parameters | group , password , type , entity |
Last Changes | Release 9.164 - added. |
The updatescript
command is used to update or create a new script inside either Corrade's inventory or inside a primitive's (task) inventory.
Command | Required Parameters | Required Corrade Permissions | Example |
---|---|---|---|
updatescript | group , password , type | inventory , interact , system | llInstantMessage(CORRADE, wasKeyValueEncode( [ // updates a script in a // primitive's inventory "command", "updatescript", "group", wasURLEscape(GROUP), "password", wasURLEscape(PASSWORD), // update a script in-world "type", "task", // the name or UUID of the // script in the primitive's // inventory. "target", "New Script", // the name of the primitive // that contains the script... "item", "My Update Object", // ...in a 5m range "range", 5, // Update script source using a text entity. "entity", "text", // Base64 encoded script data "data", wasURLEscape( "default { state_entry() { llOwnerSay(\"Hello world!\"); } } ") ] ) ); |
Parameter | Possible Value | Second Parameter | Possible Value | Optional Parameter | Possible Value | Description |
---|---|---|---|---|---|---|
type | task | item | The name or UUID of the primitive containing the script to update. | range | The range in meters where the primitive can be found. | Update or create a script inside a primitive's inventory. |
run | True (default) if the script should be set to running. |
|||||
mono | True (default) if the script should be compiled using the mono compiler. |
|||||
reset | True (default) if the script should be reset after being updated. |
|||||
target | The name of the script. | |||||
agent | item | The inventory item name or UUID of the script to create or update. | mono | True (default) if the script should be compiled using the mono compiler. |
||
target | The name of the script. | |||||
entity | text | data | The source code of the script. | Creates or updates a script using the value passed to the optional parameter data as the script source code. |
||
file | path | The path to a file on the local storage that Corrade is running off. | Creates or updates a script by reading the file passed to the optional path parameter and setting the script source code to the contents of the file. |
|||
asset | data | Base64-encoded asset data such as the one returned by the download command. | Creates or updates a script from binary asset data. | |||
create | True or False | description | A string. | The command attempts to update an existing script and if create is set to True (default is False ), then the script will first be created if it does not exist and then updated. |
The command will return the asset UUID and the inventory UUID of the created or updated script if successful, a compiled
cell set to either True
or False
depending on whether the script compiled successfully, as well as any outstanding compiler errors corresponding to a message
cell.
The reason why this command succeeds in case the script does not compile is due to the fact that transferring a script, even a broken script, to a primitive is a perfectly valid action such that the success status of the command does not reflect the status of compiling the LSL script but rather reflects the status of the execution of the updatescript
command. One would usually issue a compilescript
command in order to create a script and check whether the script compiles and only then transfer the script to a primitive. However, the updatescript
allows a sort of shorthand where the user can transfer the script, compile it and also check for any compilation errors.
The updatescript
command returns a value passed to the data
key of the callback that can be unpacked in case the compilation of the LSL script failed in order to retrieve the messages. The order of operations to retrieve the error messages would be the following:
success=True
),data
key of the command callback using wasKeyValueGet
,data
key using wasURLUnescape
,data
key to a list,compiled
within the CSV list and retrieve its value as an offset of +1
in order to ensure that the script failed to compile (index of compiled
+ 1),messages
(index of message
+ 1),messages
cell,messages
cell to a CSV list,wasURLUnescape
),Although that might seem complicated, it is easier to write in LSL code:
// check whether the command was successful if(wasURLUnescape(wasKeyValueGet("success", body)) != "True") { llOwnerSay("Command was not successful."); return; } // retrieve the value of the data key from the callback string data = wasURLUnescape(wasKeyValueGet("data", body)); // convert the value of the data key to an LSL list list values = wasCSVToList(data); // check whether the script compiled successfully string success = llList2String( values, llListFindList(values, ["compiled"]) + 1 ); if(success != "True") { // the script did not compile successfully so unpack the messages string messages = wasURLUnescape( llList2String( values, llListFindList(values, ["message"]) + 1 ) ); // convert the messages to a list of messages // multiple error messages are possible during the compilation of an LSL script list errors = wasCSVTolist(messages); do { string error = wasURLUnescape( llList2String( errors, 0 ) ); errors = llDeleteSubList(errors, 0, 0); // act upon the error message stored in the "error" variable } while(llGetListLength(errors) != 0); }
The main highlight is that Corrade will double escape the script compilation errors:
message
CSV key in order to not create any conflicts with any other data returned by the command as part of the data
KVP key,
Here is an abbreviated callback value for the updatescript
command:
command=updatescript&time=...&data=item,..,asset,..,message,(2%252C%2B23)%2B%253A%2BERROR%2B%253A%2BName%2Bnot%2Bdefined%2Bwithin%2Bscope%250A,compiled,False&success=True
The unescaping or unpacking of the error messages can be represented as an ASCII tree where each level represents an escape operation. Let's reduce the callback just to the value of the message
key and perform the operations wasURLUnescape
and wasCSVToList
in order to reduce the escaped string to a series of error messages:
%2522ERROR%25282%252C%252010%2529%253A%2520Invalid%2520syntax%2522%2C%2522ERROR%25281%252C%25204%2529%253A%2520Jump%2520out%2520of%2520scope%2522 wasURLUnescape %22ERROR%282%2C%2010%29%3A%20Invalid%20syntax%22,%22ERROR%281%2C%204%29%3A%20Jump%20out%20of%20scope%22 wasCSVToList %22ERROR%282%2C%2010%29%3A%20Invalid%20syntax%22 %22ERROR%281%2C%204%29%3A%20Jump%20out%20of%20scope%22 wasURLUnescape wasURLUnescape "ERROR(2, 10): Invalid syntax" "ERROR(1, 4): Jump out of scope"
type
is set to task
, then the command is radar-bound.