Legacy GM Can one argument get the value of another argument?

R

RealsLife

Guest
So I tried asking this yesterday but maybe I wasn't efficiënt in explaining it.

Code:
///scr_rectangle_position(key_kind,position);
position = argument1;

if(mouse_check_button_pressed(mb_left) && point_in_rectangle(mouse_x,mouse_y,x_pos+first_line-(button_size/2),y_pos*position-(button_size/2),x_pos+first_line+(button_size/2),y_pos*position+(button_size/2)))
{
key = position;
inside_region = true;
}

if(mouse_check_button_pressed(mb_left) && point_in_rectangle(mouse_x,mouse_y,x_pos+first_line-(button_size/2),y_pos*position-(button_size/2),x_pos+first_line+(button_size/2),y_pos*position+(button_size/2)))
{
gamepad_key = position;
inside_region = true;
}
This is what I want to achieve (please don't look at the if condition because it doesn't matter

What the code looks like and doesn't work:
Code:
///scr_rectangle_position(key_kind,position);
key_kind = argument0;
position = argument1;

if(mouse_check_button_pressed(mb_left) && point_in_rectangle(mouse_x,mouse_y,x_pos+first_line-(button_size/2),y_pos*position-(button_size/2),x_pos+first_line+(button_size/2),y_pos*position+(button_size/2)))
{
key_kind = position;
inside_region = true;
}
How the script will be triggered:

upload_2016-9-20_18-20-46.png

Both key and gamepad_key trigger different if statemens and switch cases... I also don't want the script to be written twice like in the first example I just want 1piece of code where I can change the KEY_KIND into KEY or GAMEPAD_KEY.

I hope someone can help me with it.
 

jo-thijs

Member
Oh, so basically, you want to do this?
https://www.tutorialspoint.com/cplusplus/passing_parameters_by_references.htm

That's not directly possible in GameMaker, but there are multiple work arounds.

Workaround 1 (the recommended):
Return the value of key_kind at the end of your script.
Now, call your script like this:
Code:
key = scr_rectangle_position(key, 1);
Workaround 2:
GameMaker cannot reference normal variables passed by arguments,
but it ca reference arrays passed by arguments using the [@] accessor.
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/accessors.html

Workaround 3:
Have some huge switch structures deciding which variable has to be written to.

PS:
This is technically seen a duplicate topic, which is against the rules.
Be careful with those.

Although, you are much clearer on what you want here.
 
R

RealsLife

Guest
Oh, so basically, you want to do this?
https://www.tutorialspoint.com/cplusplus/passing_parameters_by_references.htm

That's not directly possible in GameMaker, but there are multiple work arounds.

Workaround 1 (the recommended):
Return the value of key_kind at the end of your script.
Now, call your script like this:
Code:
key = scr_rectangle_position(key, 1);
Workaround 2:
GameMaker cannot reference normal variables passed by arguments,
but it ca reference arrays passed by arguments using the [@] accessor.
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/accessors.html

Workaround 3:
Have some huge switch structures deciding which variable has to be written to.

PS:
This is technically seen a duplicate topic, which is against the rules.
Be careful with those.

Although, you are much clearer on what you want here.
Okay yea thank you that's exactly what I wanted :eek:!
 
Top