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

GameMaker Silly Argument Issue?

For some unknown reason I am unable to create a script that can plug in different parameter names. I want to create a script that evaluates everything using the same equation. For some reason it's not evaluating whatsoever and I only get 0 back.

Just to keep this simple, I'll include a test example.

My create event initializes the value:
Code:
testValue = 0;
My step event utilizes the script:
Code:
testScript(testValue, 2, 2);
And the testScript itself looks like this:
Code:
argument0 = argument1 + argument2;
I kinda have a feeling that it's taking the value of testValue (which is 0) and evaluating like this:

0 = 2 + 2;

Assuming that is the case, I'll need a literal string value pushed into the script. Other than that, the code looks perfectly fine to me yet... it doesn't work! Can anyone tell me what am I doing wrong here? I appreciate it.
 
You can't pass in a variable and use the corresponding argument variable to refer to the original variable. Argument0 is now a copy of testValue, in your case, so altering argument0 will not touch testValue. Simply use the actual variable testValue within your script, instead of argument0.
 

FrostyCat

Redemption Seeker
This code immediately looks wrong to anyone who understands how arguments are passed in GML. Numeric and string arguments are passed by value, while arrays and data structures are passed by reference. If you don't know what these mean, watch this.

Either you drop the first argument and do this explicitly:
Code:
testValue = argument0 + argument1;
Code:
testScript(2, 2);
Or leverage variable_instance_set():
Code:
variable_instance_set(id, argument0, argument1+argument2);
Code:
testScript("testValue", 2, 2);
 
You can't pass in a variable and use the corresponding argument variable to refer to the original variable. Argument0 is now a copy of testValue, in your case, so altering argument0 will not touch testValue. Simply use the actual variable testValue within your script, instead of argument0.
It was just as I suspected. Lesson learned.

...Or leverage variable_instance_set():
Code:
variable_instance_set(id, argument0, argument1+argument2);
Code:
testScript("testValue", 2, 2);
Fascinating! That gives me something else to experiment with. Just needed a little nudge in the right direction. :)

Edit: I tested the variable_instance_set() and it did exactly what I wanted! Kudos!

I thank both of you for clearing things up!
Cheers!
 
Last edited:
Top