• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Using argument[0] Instead Of argument0 Causing Problems In Scripts

For some reason when I use arguments with [] in this GML script, I get a an error message saying "Script: scr_check_proper_keywords at line 1 : no references to argument 0 but references arguments 1,2,3,4,5,6,7,8"

However, when I use argument0 (the built-in constant) it works.

Here is my current script, it is designed to acquire ds_list values from another script.

Code:
/// @function scr_check_proper_keywords( keyword_is_seen, keyword_is_used, proper_keyword_ds_list, not_used_string, counter, display_error_message, TEXT_POSITION_STRING, TEXT_POSITION_VALUE, text)
///    @description Checks the Keyword value and updates keyword ds_list in draw_text_using_markup scripts
/// @param {real} keyword_is_seen whether the keyword was seen
/// @param {bool} keyword_is_used whether the keyword had already been used
/// @param {real} proper_keyword_ds_list The proper keyword ds list in the script
/// @param {string} not_used_string specific string for if a keyword is not used
/// @param {real} counter The instance for whent eh keyword was seen
/// @param {bool} display_error_message to display the error message
/// @param {real} TEXT_POSITION_STRING Denotes position in ds list where current string is located
/// @param {real} TEXT_POSITION_VALUE Denotes position in ds list where current value is located
/// @param {string} text The text to inset into ds_list

if (argument0) /*<------If I were to use "argument[0]" here and use [] for the other arguments, GMS displays an error*/
{
    //if text value used is false and value is found in ds_list and instance value is -1
    if (!argument1
    && argument2[| argument6] == argument3
    && argument2[| argument7] == -1)
    {
        //set to true
        argument1 = true;
        //increment proper keyword counter
        argument4++;
        //add values to ds_list
        ds_list_replace(argument2,argument6,argument8);
        ds_list_replace(argument2,argument7,argument4);
        
    }
    //This text value has already been declared for this textbox! Throw an error
    else {argument5 = true;}
}
 
Hmm... Here's some additional findings. When I use, say argument[2][| argument[6]] == argument[3] (an accessor for a ds_list), I get even more errors...

The following code yields the following errors:
Code:
if (argument[0])
{
    //if header is used is false and value is found in ds_list and instance value is -1
    if (!argument[1]
    && argument[2][| argument[6]] == argument[3]
    && argument[2][| argument[7]] == -1)
    {
        //set to true
        argument[1] = true;
        //increment proper keyword counter
        argument[4]++;
        //add values to ds_list
        ds_list_replace(argument[2],argument[6],argument[8]);
        ds_list_replace(argument[2],argument[7],argument[4]);
       
    }
    //A header has already been declared for this textbox! Throw an error
    else {argument[5] = true;}
}
Compile Error messages:
Script: scr_check_proper_keywords at line 17 : got '[|' expected ')'
Script: scr_check_proper_keywords at line 17 : malformed assignment
Script: draw_text_using_markup at line 123 : function "scr_check_proper_keywords" expects 1 arguments, 9 provided
Script: draw_text_using_markup at line 124 : function "scr_check_proper_keywords" expects 1 arguments, 9 provided
Script: draw_text_using_markup at line 125 : function "scr_check_proper_keywords" expects 1 arguments, 9 provided
Script: draw_text_using_markup at line 126 : function "scr_check_proper_keywords" expects 1 arguments, 9 provided
Script: draw_text_using_markup at line 127 : function "scr_check_proper_keywords" expects 1 arguments, 9 provided
Script: scr_check_proper_keywords at line 16 : malformed if statement

Question:
Does using argument constants with the [] array designation and ds_list accessors (list_name[| index]) cause errors in scripts? Has it been an issue in the past?

line 17 works if I use argument2[| argument6] == argument[3]
However, causes error if: argument[2][| argument[6]] == argument[3]
 

TailBit

Member
to access the arrays there, you might want to put them into var's first:


Code:
var a = argument[2];

// ...

    && a[| argument[6]] == argument[3]
    && a[| argument[7]] == -1)
The arguments are a copy of the originals.
argument[5] = true;
so setting them to a value doesn't work

except for accessors

you might want to return a value instead:

value = script( ... ,value, ...)

and where you set argument to true:
return true
and
return argument[5]
at the end
 
Last edited:
to access the arrays there, you might want to put them into var's first:


Code:
var a = argument[2];

// ...

    && a[| argument[6]] == argument[3]
    && a[| argument[7]] == -1)
The arguments are a copy of the originals.
argument[5] = true;
so setting them to a value doesn't work

except for accessors

you might want to return a value instead:

value = script( ... ,value, ...)

and where you set argument to true:
return true
and
return argument[5]
at the end
Oh yeah... I forgot that GML scripts only return values if using the return keyword and passing the value out. I wish you could use the ptr() cast to actually cast a memory reference to the actual variables and modify them in the scope of a script. Otherwise, returning multiple values is a pain because you have to return an array meaning extra work.

C# allows you to use ref when passing values into and out of a method. You can still return a specific value but you can simultaneously modify an non-returned value within the method and pass its changes out because you used the ref keyword. It's very convenient. I would highly recommend something similar as a future upgrade for GMS.

Hmm... so when using the [ ] indices of the arguments, you must assign them to temp variables in the script otherwise errors might occur? Functionally, there should be no difference between argument0 and argument[0].

Oh well.
 

FrostyCat

Member
Hmm... so when using the [ ] indices of the arguments, you must assign them to temp variables in the script otherwise errors might occur? Functionally, there should be no difference between argument0 and argument[0].
Where did you learn this myth from? There's a huge difference between argument0 and argument[0].

If you reference arguments using the argumentn syntax, this makes the script accept a fixed number of arguments. Every argument from argument0 through argumentn (whichever you stop at) must be referenced at least once inside the script, or you get a compile-time error.

If you reference arguments using the argument[n] syntax, this makes the script accept a variable number of arguments. You don't have to reference every index this time, though you will still get a runtime error if you try to reference arguments that have not been given.

Accessors are not yet chainable (though will be in early 2020), so your argument[2][| argument[6]] expression is too far ahead of its time for trying to chain [] to [| ]. This can be worked around by assigning argument[2] to a temporary variable and using an accessor on that as TailBit described. argument2[| argument[6]] doesn't have this issue, and this will remain another difference between the two argument syntaxes until next year.
 
Top