-
Notifications
You must be signed in to change notification settings - Fork 8
Complex command arguments
In addition to strings and numbers, the console accepts XML and objects in JSON notation.
Say you have a function, addGuy(fullname:String,age:int) linking it to the command, "addGuy". In this case, the fullname string likely has at least one space in it. To separate the fullname argument from the age argument (and avoid the full name and age being concatenated into one string arg, which is what the console does as a last resort at an argument count mismatch), use " or ' as such:
addGuy "Andreas Rønning" 27
To supply an XML argument, simply use XML notation
myCommand <data><node/></data>
Arrays and object arguments rely on the JSONParserUtil plugin, enabled as such DConsole.registerPlugins(JSONParserUtil);
To supply an array argument, use ActionScript bracket syntax:
myCommand [1,5,6,2]
In the same way, to supply an object argument, use JSON object notation as such:
myCommand {"firstname":"Andreas","lastname":"Rønning"}
You'll notice that JSON notation differs slightly from ActionScript in that it wraps property names in quotes. For more information on JSON, go to http://www.json.org
Objects can contain arrays, and arrays can contain objects. Both the array and object parsing is handled by JSON, so the two are free to be mixed. You can imagine the horror of typing out objects of this complexity, but the option is there:
myCommand [{"myArray":[{"firstname":"andreas","lastname":"rønning"}]}]
Preparsed XML and subcommand results are currently not available for inclusion in objects or arrays.