1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 [HELP] Utterly Baffled at script_execute()

Discussion in 'Programming' started by CannedSmeef, Jan 13, 2018.

  1. CannedSmeef

    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: Jan 13, 2018
  2. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    317
    Can you post the code where you're calling the function.
     
  3. CannedSmeef

    CannedSmeef Guest

    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);
    
     
  4. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    317
    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);
    
     
  5. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,043
    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;
    }
     
  6. CannedSmeef

    CannedSmeef Guest

    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
     
  7. CannedSmeef

    CannedSmeef Guest


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

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,043
    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?
     
  9. CannedSmeef

    CannedSmeef Guest

    Yes I have, every time I get to script_execute() in the step, it will immediately execute the first script in the list
     
  10. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,698
    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));
     
  11. CannedSmeef

    CannedSmeef Guest

    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);
    
     
  12. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,698
    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.
     
  13. CannedSmeef

    CannedSmeef Guest

    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;
    }
    
     
  14. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,698
    *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.
     
  15. CannedSmeef

    CannedSmeef Guest

    ...There are no lines that do this in any of my code. At all. Those two aren't variables, they're scripts.
     
  16. JFitch

    JFitch Member

    Joined:
    Sep 28, 2016
    Posts:
    428
    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?
     
  17. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    665
    He already mentioned that he was assigning scripts to that variable. Not strings. Don't make him repeat again.
     
  18. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    317
    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...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice