Legacy GM [HELP] Utterly Baffled at script_execute()

C

CannedSmeef

Guest
Why on earth does the order of the scripts matter? No matter what I put into script_execute() it will always execute the first script instead. And my whole game will break unless I have a specific script first.

Ways to fix this?

EDIT:

So... I restarted gamemaker and it's totally fine now. No issues whatsoever.

I'm so confused.
 
Last edited by a moderator:
C

CannedSmeef

Guest
Can you post the code where you're calling the function.
Code:
// CREATE EVENT:
globalvar useMoveScript;

if (gamepad_is_connected(0)) {
    useMoveScript = asset_get_index(gamepad_movement);
}
else {
    useMoveScript = asset_get_index(keyboard_movement);
}

// STEP EVENT:
script_execute(useMoveScript);
 

Paskaler

Member
asset_get_index takes a string as an argument and is not necesarry here, just remove the asset_get_index and that's it.

Code:
// CREATE EVENT:
globalvar useMoveScript;

if (gamepad_is_connected(0)) {
   useMoveScript = gamepad_movement;
}
else {
   useMoveScript = keyboard_movement;
}

// STEP EVENT:
script_execute(useMoveScript);
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Why are you using asset_get_index? That's not required as you can simply do:

Code:
// CREATE EVENT:
globalvar useMoveScript;

if (gamepad_is_connected(0)) {
   useMoveScript = gamepad_movement;
}
else {
   useMoveScript = keyboard_movement;
}
 
C

CannedSmeef

Guest
asset_get_index takes a string as an argument and is not necesarry here, just remove the asset_get_index and that's it.
Oh apologies, this is my recent attempt to "fix" it, not the original. This doesn't work at all.

The original will simply assign the useMoveScript to the script name and that's it. But no matter what it's set to script_execute will always execute the first
 
C

CannedSmeef

Guest
Why are you using asset_get_index? That's not required as you can simply do:

Code:
// CREATE EVENT:
globalvar useMoveScript;

if (gamepad_is_connected(0)) {
   useMoveScript = gamepad_movement;
}
else {
   useMoveScript = keyboard_movement;
}

Sorry I posted an attempt of me fixing the problem, what you have written is exactly what the original was.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Then maybe the problem is with the gamepad check? Have yu run the code in the debugger and stepped though each line to make sure that what you think is happening is what is really happening?
 
C

CannedSmeef

Guest
Then maybe the problem is with the gamepad check? Have yu run the code in the debugger and stepped though each line to make sure that what you think is happening is what is really happening?
Yes I have, every time I get to script_execute() in the step, it will immediately execute the first script in the list
 

FrostyCat

Redemption Seeker
What are you assigning to gamepad_movement and keyboard_movement? You clearly have a garbage-in-garbage-out problem. Your first priority should be to figure out what garbage is coming in to make those variables hold a reference to the first script, not what's wrong with script_execute().

Here are the two main correct setups:

If you are assigning a raw script ID (i.e. WITHOUT brackets after the script's name):
Code:
gamepad_movement = scr_xbox_gamepad;
Then pass it into script_execute() as-is:
Code:
script_execute(gamepad_movement);
If you are assigning a string to the variable:
Code:
gamepad_movement = ini_read_string("settings", "movement_control", "scr_xbox_gamepad");
Then you should use asset_get_index() first:
Code:
script_execute(asset_get_index(gamepad_movement));
 
C

CannedSmeef

Guest
What are you assigning to gamepad_movement and keyboard_movement? You clearly have a garbage-in-garbage-out problem. Your first priority should be to figure out what garbage is coming in to make those variables hold a reference to the first script, not what's wrong with script_execute().

Here are the two main correct setups:

If you are assigning a raw script ID (i.e. WITHOUT brackets after the script's name):
Code:
gamepad_movement = scr_xbox_gamepad;
Then pass it into script_execute() as-is:
Code:
script_execute(gamepad_movement);
If you are assigning a string to the variable:
Code:
gamepad_movement = ini_read_string("settings", "movement_control", "scr_xbox_gamepad");
Then you should use asset_get_index() first:
Code:
script_execute(asset_get_index(gamepad_movement));
I appreciate the help, but I'm already doing method one.

Code:
// CREATE:
weapon_list();

weaponNumber = 0;
currentWeapon = weapons[weaponNumber];

playerSpeed = 5;

alarm[0] = 60;
alarm[1] = 30;
alarm[2] = 300;

globalvar points;
points = 0;

globalvar useMoveScript;

if (gamepad_is_connected(0)) {
    useMoveScript = gamepad_movement;
}
else {
    useMoveScript = keyboard_movement;
}

// STEP:
script_execute(useMoveScript);
 

FrostyCat

Redemption Seeker
I appreciate the help, but I'm already doing method one.

Code:
// CREATE:
weapon_list();

weaponNumber = 0;
currentWeapon = weapons[weaponNumber];

playerSpeed = 5;

alarm[0] = 60;
alarm[1] = 30;
alarm[2] = 300;

globalvar points;
points = 0;

globalvar useMoveScript;

if (gamepad_is_connected(0)) {
    useMoveScript = gamepad_movement;
}
else {
    useMoveScript = keyboard_movement;
}

// STEP:
script_execute(useMoveScript);
I asked you what is being assigned to gamepad_movement and keyboard_movement, you have not answered that question.

Now do as I asked and post the part of the code that sets the value for these variables. Chances are you did that part wrong.
 
C

CannedSmeef

Guest
I asked you what is being assigned to gamepad_movement and keyboard_movement, you have not answered that question.

Now do as I asked and post the part of the code that sets the value for these variables. Chances are you did that part wrong.
Code:
// gamepad_movement
axis = gamepad_axis_value(0, gp_axislv);

if (abs(axis) > 0.2) {
    y += round(playerSpeed * axis);
    y = clamp(y, 0+sprite_height / 2, room_height - sprite_height / 2);
}
// keyboard_movement
//Shortcuts for keypresses
MOVEUP = keyboard_check(vk_up);
MOVEDOWN = keyboard_check(vk_down);

if (MOVEUP && y > sprite_width/2) {
    y -= playerSpeed;
}

if (MOVEDOWN && y < room_height - sprite_width/2) {
    y += playerSpeed;
}
 

FrostyCat

Redemption Seeker
Code:
// gamepad_movement
axis = gamepad_axis_value(0, gp_axislv);

if (abs(axis) > 0.2) {
    y += round(playerSpeed * axis);
    y = clamp(y, 0+sprite_height / 2, room_height - sprite_height / 2);
}
// keyboard_movement
//Shortcuts for keypresses
MOVEUP = keyboard_check(vk_up);
MOVEDOWN = keyboard_check(vk_down);

if (MOVEUP && y > sprite_width/2) {
    y -= playerSpeed;
}

if (MOVEDOWN && y < room_height - sprite_width/2) {
    y += playerSpeed;
}
*FACEPALM*

Are you trying to troll me? This is not what I asked for, and this is the third time I have to explain myself. I asked you to post the part of your code that sets values for gamepad_movement and keyboard_movement, not what's in the scripts.

There should be two lines in your code looking like the following:
Code:
gamepad_movement = ???;
Code:
keyboard_movement = ???;
Post those two lines already. Don't make me repeat myself again.
 
C

CannedSmeef

Guest
*FACEPALM*

Are you trying to troll me? This is not what I asked for, and this is the third time I have to explain myself. I asked you to post the part of your code that sets values for gamepad_movement and keyboard_movement, not what's in the scripts.

There should be two lines in your code looking like the following:
Code:
gamepad_movement = ???;
Code:
keyboard_movement = ???;
Post those two lines already. Don't make me repeat myself again.
...There are no lines that do this in any of my code. At all. Those two aren't variables, they're scripts.
 
J

JFitch

Guest
game_pad_movement and keyboard_movement are clearly script names

If the first script is being executed, that means you're using script_execute(0). Is it possible that useMoveScript is somehow being set to 0 in another event?
 
C

CedSharp

Guest
*FACEPALM*

Are you trying to troll me? This is not what I asked for, and this is the third time I have to explain myself. I asked you to post the part of your code that sets values for gamepad_movement and keyboard_movement, not what's in the scripts.

There should be two lines in your code looking like the following:
Code:
gamepad_movement = ???;
Code:
keyboard_movement = ???;
Post those two lines already. Don't make me repeat myself again.
The original will simply assign the useMoveScript to the script name and that's it.
He already mentioned that he was assigning scripts to that variable. Not strings. Don't make him repeat again.
 

Paskaler

Member
A note:

Code:
// CREATE EVENT:
globalvar useMoveScript;

if (gamepad_is_connected(0)) {
   useMoveScript = asset_get_index(gamepad_movement);
}
else {
   useMoveScript = asset_get_index(keyboard_movement);
}

// STEP EVENT:
script_execute(useMoveScript);
This would've given error if you didn't set gamepad_movement/keyboard_movement somewhere before. It would've given you an undefined reference(I know you changed script since then).

EDIT: Nevermind...
 
Top