returning an argument in a script, gone wrong I guess?

R

RealsLife

Guest
Code:
position = argument0;
key_kind = 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;
}

return argument1;
This code doesn't work at all... so the function would be scr_rectangle_position(key,1); and after this script a switch with key is triggered but this script only works if I don't use a script but rather write the code in the object step event itself with

Code:
position = 1;
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 = 1;
inside_region = true;
}
What can I do to make the script work o_O?
 

Bingdom

Googledom
(return argument1) returns back what you have inputted to the script. ;)

You don't always need the return function inside a script, try going without it and see what happens. ;)
 
R

RealsLife

Guest
Well I first tried to do it without return but it also didn't work, I want to input key and position into the function and that it return the value of key so my switch case further in the code can do somthing with it

Ugh anyone else that has info xD?
 
Last edited by a moderator:
Ugh anyone else that has info xD?
You seem to be wanting your script to return two values. This isn't possible just using return. You can just let the code modify the variables normally without using return. You seem to be passing key_kind into the script but not actually using it.

So your script should look like this...

Code:
position = argument0;

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;
}
Your call would just be...
Code:
scr_script_name(1);
After this script is run, the value of key_kind should be 1 and inside_region would be 1/true (assuming your mouse check is true).

Edit: You should also review the documentation on scripts: https://docs.yoyogames.com/source/dadiospice/001_advanced use/006_scripts.html
 
Last edited:
R

RealsLife

Guest
You seem to be wanting your script to return two values. This isn't possible just using return. You can just let the code modify the variables normally without using return. You seem to be passing key_kind into the script but not actually using it.

So your script should look like this...

Code:
position = argument0;

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;
}
Your call would just be...
Code:
scr_script_name(1);
After this script is run, the value of key_kind should be 1 and inside_region would be 1/true (assuming your mouse check is true).

Edit: You should also review the documentation on scripts: https://docs.yoyogames.com/source/dadiospice/001_advanced use/006_scripts.html
I also need to identify the other variable the key because the gamepad uses another variable as key
so for example when I use keyboard the variable is named key if I use gamepad it's called gamepad_key that's why I put the variable in it.

The type of key triggers 2different switch statemens.
 
Last edited by a moderator:
I also need to identify the other variable the key because the gamepad uses another variable as key
so for example when I use keyboard the variable is named key if I use gamepad it's called gamepad_key that's why I put the variable in it.

The type of key triggers 2different switch statemens.
Both key_kind and inside_region are set by this script. I don't see the issue. Scripts CAN modify values outside of them without using Return.
 
R

RealsLife

Guest
Both key_kind and inside_region are set by this script. I don't see the issue. Scripts CAN modify values outside of them without using Return.
I know but the issue is that for example if I only use position,
Code:
 switch(key)
    {
        case 1:
        key1 = newKey;
        key1_description = key1;
        if(key != 0){key = 0; count1 = 0; inside_region = false;}
        break;
}
This will now work, but...


Code:
switch(gamepad_key)
    {
        case 1:
        key1 = newKey;
        key1_description = key1;
        if(gamepad_key != 0){key = 0; count1 = 0; inside_region = false;}
        break;
   }
Now the content of these isn't important just the trigger who activates the switch statements

Edit: When thinking now about it I should have asked you guys this to get a good answer... Is it possible to give a variable name from the outside of the script like key = 0; and pass the name key trough the arguments in the selfmade script so that 1argument key will get the new value of the second argument. This way I can change the arguments variable name and trigger other events outside of the script because of the different variable name needed. At least this is whay I tried in the script to get working. It also failed so help please :p!
 
Last edited by a moderator:
Top