Legacy GM [Solved]Creating Instance for Non-Existing Object: 99

I

Irishes

Guest
So, I have recently ran into this error and I've had trouble diagnosing it. I have a player object which draws an array of 'factions' above it. When the select button is pressed, the current index is saved into a variable called 'selectedFaction'. The string value of this passed into a script; scr_create_faction_player(id), which creates the correct player and destroys the object that created it. Then that faction player draws an array of available ships to that faction. The same thing happens and when the select button is pressed, the string value of the current index is passed into a script called scr_create_ship(id). However this is when I get the error listed in the title of this post. I apologize if my explanation is not very clear. Thank you in advance.

The Player that creates the Ship

Code:
/// Draw Ship Array
// Draw Self and the Array at index
draw_self();
draw_set_color(c_white);
draw_text(x-16, y-32, obj_game_values.militiaArray[index]);

// Checks if Controller is Connected
if(gamepad_is_connected(controllerNum)){
    gamepad_set_axis_deadzone(controllerNum, .5);
    
    // Move index forward 1
    if(gamepad_button_check_pressed(controllerNum, gp_padr)){
        if(index >= array_length_1d(obj_game_values.rebelArray)-1){
            index = 0;
        } else {
            index += 1;
        }
    }

    // Move index backward 1
    if(gamepad_button_check_pressed(controllerNum, gp_padl)){
        if(index <= 0){
            index = array_length_1d(obj_game_values.militiaArray)-1;
        } else {
            index -= 1;
        }
    }
    
    // Set selectedShip to current index
    if(gamepad_button_check_pressed(controllerNum, gp_face1)){
        selectedShip = string(obj_game_values.militiaArray[index]);
        script_execute(scr_create_ship(id));
        instance_destroy();
    }
}
The Code that creates the Ship

Code:
// Sets selectedShip to Object of Ship
/// scr_create_ship(id)
// Takes in id
argument0 = id;

// Militia
if(selectedShip == "Ship0"){
    selectedShip = obj_ship0;
}
if(selectedShip == "Ship1"){
    selectedShip = obj_ship1;
}
if(selectedShip == "Ship2"){
    selectedShip = obj_Ship2;
}

// Creates ship and passes Faction and controllerNum into it
instance = instance_create(x, y, selectedShip);
instance.controllerNum = id.controllerNum;
 
Several things before addressing the main concern.

1) The deadzones only needs to be set once, so just set them at the start of the game.

2) With the way you're calling the scr_create_ship script, you don't need the script_execute function. The way to properly use that function would have been

Code:
script_execute(scr_create_ship,id);
but it's not necessary in this case.

3) The ship creation script has a few issues. You pass in an argument, in this case the id. However, you then set the argument to be the id anyway, so it removes the need to pass it in. Then, you don't even use the argument but call the id directly, and with that, you can just get rid of the id prefix altogether.


I don't understand what your militiaArray array actually stores. It looks like you have some resource indexes stored in it because you're converting them to a string when you press the A button. I'm guessing sprites? In any case, it's all unnecessary. Unless you're using the script elsewhere (which I can't imagine), you can ditch it altogether and just use the index variable, with this being one example.

Code:
if(gamepad_button_check_pressed(controllerNum, gp_face1)){
       instance_create(x,y,asset_get_index("obj_ship"+string(index));
       instance_destroy();
}
 
Top