• 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!

Legacy GM Scripts and argument_count

P

Pepasone

Guest
I'm passing arguments to a script with this:
GML:
script_execute(scr_itemcreation, item_avoid, item_armor, item_resist);
I'm then trying to do this with said variables:

Code:
// Create variation in item stats
if argument_count > 0
{
    for (i = 0; i < argument_count; i++)
    {
        if argument[i] <= 10
        {
            argument[i] += irandom_range(-2, 2);
        }
        
        else if argument[i] <= 30
        {
            argument[i] += irandom_range(-3, 3);
        }
        
        else if argument[i] <= 40
        {
            argument[i] += irandom_range(-4, 4);
        }
        
        else
        {
            argument[i] = round(argument[i] * (1.1 - random(.2)));
        }
    }
}
It isn't doing anything, but it also isn't throwing any errors. Why would that be?
 

Nidoking

Member
The arguments are passed by value, meaning that inside the script, you're only working with a copy of the values of those variables, not the variables themselves. You'd have to return the values you want to use somehow. You can either put them in an array, return the array, and then copy the values to the variables, or pass an instance id that has those values and store them in the instance. Another thing you can do is use the script individually for each variable i.e. item_avoid = scr_itemcreation(item_avoid). (This also requires you to return the value explicitly, but at least you'd only need to return one thing at a time.)

This assumes that what you've shown is the entire script, which seems a bit strange.
 

Zhanghua

Member
The function or scripte default passes the arguments by value only while not the reference.
Other wise you pass the variable of ds_xxx seriers ,or array used by the method of accessor @.
 
P

Pepasone

Guest
Thanks to both of you, looks like I will have to evaluate each stat one at a time!
 
Top