Error: Anyone can help?

Hi there. So I started using this tutorial so I can get physics similar to SMB1 but I tried to run it and this happens:

ERROR in
action number 1
of Step Event0
for object obj_player:

Variable input.<unknown variable>(100010, -2147483648) not set before reading it.
at gml_Object_obj_player_Step_0 (line 4) - move = input.left + input.right;
############################################################################################
gml_Object_obj_player_Step_0 (line 4)

I looked over my variables in input and see nothing misspelled, at least that's what my eyes tell me haha.

My "input" Code:
GML:
///Check for inputs

up = keyboard_check(vk_up);
down = keyboard_check(vk_down);
right = keyboard_check(vk_right);
left = - keyboard_check(vk_left);
start = keyboard_check(vk_enter);
select = keyboard_check(vk_tab);
a = keyboard_check(ord("A"));
b = keyboard_check(ord("S"));
Here's my "Step" code for obj_player:
Code:
/// Main Actions

// Movement
move = input.left + input.right;

    // Move Right
    if (move == 1)
    {
        hsp += acc;
        if (hsp >= maxSpeed) hsp = maxSpeed;
    }
    else if (hsp > 0)
    {
        hsp -= acc;
        if (hsp <= 0) hsp = 0;
    }

    // Move Left
    if (move == -1)
    {
        hsp -= acc;
        if (hsp <= -maxSpeed) hsp = -maxSpeed;
    }
    else if (hsp < 0)
    {
        hsp += acc;
        if (hsp >= 0) hsp = 0;
    }
    
// Gravity
if (vsp < 5) vsp += grav;

if (place_meeting(x, y+1, obj_wall)) vsp = 0;

x += hsp;
y += vsp;
Also another thing, Ga,meMaker 2 doesn't have "instance_create". Instead, it has "instance_create_depth" and "instance_create_layered" which one would I use for this and why? That could be why its not working right

Here's my obj_main "create" code:
Code:
/// Set input
instance_create_layer(x,y,1,input);
The help would be much appreciated. Thanks beforehand if you read to this point.

Here's the tutorial if you'll would like to see it:
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, first, why not check the manual to see what each of the different instance_create_layer/depth functions does?
THEN you'll find why the instance "input" doesn't exist and you're getting this error... ;)
 
Okay, first, why not check the manual to see what each of the different instance_create_layer/depth functions does?
THEN you'll find why the instance "input" doesn't exist and you're getting this error... ;)
This might make me sound even dumber but I read it yet still didn't understand.
I assume I'm right using instance_create_layer from the description as the depth one I don't need but I don't understand the layer ID.
Am I supposed to name do (x, y, "instance_layer", input) or would something else be the name of it?
Haha I'm very stupid when it comes to code that's why I stick more towards the art side of things
 

TailBit

Member
Do you have the variables in the create event too?

If not then they won't exist until the step event happens, and if the player object was put into the room before the control object, then the player will trigger its step event first, and it won't find the variables..

You can find the layer name in the room editor, if you want something sorter then just rename it.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Am I supposed to name do (x, y, "instance_layer", input) or would something else be the name of it?
Yup! That's it, just use the name of the layer (in quotes) for the layer you want to create the instance on. For example id the room editor has a layer called "controller_instances" then you'd do:
GML:
instance_create_layer(x, y, "controller_instances", input);
So, just to clarify a little... The create layer function can take the NAME of the layer (a string in quotes) or the ID of a layer, which would be a number (you can use the function layer_get_id() to retrieve this number). So, when you used the number 1 as the layer in the function in your code, the game tried to create the input instance on a layer with the ID 1. BUT this layer ID won't exist (as that's not how layers are numbered) and so the instance is never created. This in turn means that your code that accesses the variables in the instance won't work, which gives you the error you got. :)

Hope that helps!
 
Yup! That's it, just use the name of the layer (in quotes) for the layer you want to create the instance on. For example id the room editor has a layer called "controller_instances" then you'd do:
GML:
instance_create_layer(x, y, "controller_instances", input);
So, just to clarify a little... The create layer function can take the NAME of the layer (a string in quotes) or the ID of a layer, which would be a number (you can use the function layer_get_id() to retrieve this number). So, when you used the number 1 as the layer in the function in your code, the game tried to create the input instance on a layer with the ID 1. BUT this layer ID won't exist (as that's not how layers are numbered) and so the instance is never created. This in turn means that your code that accesses the variables in the instance won't work, which gives you the error you got. :)

Hope that helps!
Do you have the variables in the create event too?

If not then they won't exist until the step event happens, and if the player object was put into the room before the control object, then the player will trigger its step event first, and it won't find the variables..

You can find the layer name in the room editor, if you want something sorter then just rename it.
Thank you both. It's working now and I couldn't be happier! I doubt this will be the last time I'm stupid haha
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Thank you both. It's working now and I couldn't be happier! I doubt this will be the last time I'm stupid haha
Happy to help! And please, we've all "been stupid" at one point (and I still can be!!!). Just ask your questions and don't worry about it... we've all had to learn the same way. :)
 
Top