Pfap
Member
I have been over the manual sections about scripts and passing arrays to scripts. Maybe I missed something, but I'm making this posting not because I'm having trouble finding a solution I already know of several work arounds. I'm making this posting, because I want to finally figure out how to get a variable number of arguments working with scripts cleanly.
Here's the relevant code.
Script create_popup:
And here is how I am calling it:
This proceeds to crash, because none of my var's are being set in the beginning of the script. Also, the argument_count variable is displaying 1 in the console output. Which I take to mean that the array of 5 arguments is being accepted as 1 array.
This is the portion of the manual that has me confused on how to use the built in argument[n] array.
tl;dr
How do you use the built in argument[n] array to create variable argument scripts?
Here's the relevant code.
Script create_popup:
Code:
show_debug_message(argument_count);
if argument_count == 5{
var xpos = argument[0];
var ypos = argument[1];
var text = argument[2];
var button_amount = argument[3];
var b_string = argument[4];
show_debug_message(b_string);
}
if argument_count == 6{
var xpos = argument[0];
var ypos = argument[1];
var text = argument[2];
var button_amount = argument[3];
var b_string = argument[4];
var c_string = argument[5];
show_debug_message(b_string);
show_debug_message(c_string);
}
Code:
//create an array with desired amount of arguments
var args = [room_width/2,room_height/2,"Are you sure?",1,"Ok"]
create_popup(args);
This is the portion of the manual that has me confused on how to use the built in argument[n] array.
However you can supply a variable number of arguments to a script using the built in argument array, and you are not limited to a maximum of 16 arguments either when using this array, but instead can have as many as you require (although, again, you must ensure that all arguments are referenced within the script):
argument[0 ... max_num]
When passing in a variable number of arguments as an array of values you can use the following function:
This can be used to find out how many arguments have been passed and adapt the script to use only those arguments supplied.
NOTE: You cannot mix the two types of argument variables when calling a script. You must use either argument0...15 or argument[n].
Scripts can also return a value, so that they can be used in expressions. For this you would use the return statement:
tl;dr
How do you use the built in argument[n] array to create variable argument scripts?