• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Illegal access of argument in script

S

Squirtle Plays

Guest
When I attack it triggers this error
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object object3:

illegal access of argument, argument is not provided to script
at gml_Script_PlayerState_Attack_Stab (line 6) - if (sprite_index != argument[0])
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_PlayerState_Attack_Stab (line 6)
called from - gml_Object_object3_Step_0 (line 66) - case PLAYERSTATE.ATTACK_STAB: PlayerState_Attack_Stab(); break;
Here's the code that triggers the script
GML:
switch (state)
{
    
    case PLAYERSTATE.FREE: PlayerState_Free() break;   
    case PLAYERSTATE.ATTACK_STAB: PlayerState_Attack_Stab() break;
    
}
and here is the script
GML:
hspeed = 0;
vspeed = 0;

//Start of the attack
hitByAttack = ds_list_create();
if (sprite_index != argument[0])
{
    sprite_index = argument[0]
    image_index = 0;   
    ds_list_clear(hitByAttack);
}

//Use attack hitbox & check for hits
mask_index = argument[1];
var hitByAttackNow = ds_list_create()
var hits = instance_place_list(x,y,o_yeah,hitByAttackNow,false);
if (hits > 0)
{
    for (var i = 0; i < hits; i++)
    {
        //if this instance has not yet been hit by this attack, hit it
        var hitID = hitByAttackNow[| i]
        if (ds_list_find_index(hitByAttack,hitID) == -1)
        {
            ds_list_add(hitByAttack,hitID);
            with (hitID)
            {
                EnemyHit(2);
            }
        }
    }
}
ds_list_destroy(hitByAttackNow);
mask_index = sprite01;

if (Animation_End())
{
    sprite_index =     sprite01;
    state = PLAYERSTATE.FREE;
}
I tried looking around but nobody else's error applied
 
H

Homunculus

Guest
Your script uses the arguments array, so I assume you want the arguments to be optional. The problem is that you still use them in your computations, and that's probably causing the "illegal access of argument" exception. You need to either pass the arguments to the script, and treat them as required, or actually make them optional by checking inside the script if they are set before using them. If not, define what happens by default.
 
S

Squirtle Plays

Guest
I'm sorry I'm a complete novice when it comes to GML I coded most of this using a tutorial could you elaborate more on how I could do this sorry if I didn't express how much of a novice I am.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Your script references argument[0] and argument[1]. It therefore uses arguments, but you are not providing any arguments in the call to the script. Technically it does not require arguments, as they are optional due to the usage of the argument array rather than direct arguments, but your code uses them unconditionally, so while supplying them is not required, your code will still crash because you attempt to use them even though they were not passed.
 
S

Squirtle Plays

Guest
I'm sorry if this is a stupid question but how do I pass them
 

TsukaYuriko

☄️
Forum Staff
Moderator
case PLAYERSTATE.FREE: PlayerState_Free() break;
See the pair of parentheses in this code? Arguments go in between those.

Now, if you're asking questions like the one above, I do have to ask whether it is you who made this code, or if you're copying someone else's code without really knowing how it works.
If it's the former, I can suggest some manual pages to read in order to get a better overview of how GML works.
If it's the latter... I heavily suggest to abort whatever you're trying to do with this and take your time to learn the language before trying to apply it and use ready-made assets without understanding the basic principles.
 

Yal

🐧 *penguin noises*
GMC Elder
"argument is not provided to script" means you don't give the script any arguments.

Or more visually explained:
1585854218818.png

Put the right things there and the script will work properly (if you copypasted it properly :p)
 
S

Squirtle Plays

Guest
If I continue like this I'll probably have more problems like it in the future that I can't solve. Well at least now is the perfect time to learn because I can't leave my home. Maybe this thread can be a reminder to people who have this same error and copy code to never do it again.
 
Top