• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[solved]someone can help me with a lever

  • Thread starter Matias Fernandez
  • Start date
M

Matias Fernandez

Guest
does anyone know what's wrong?
I am trying to make a sign that says yes or no, where when I press the Z key in yes the lever goes down and when I press the Z in No the lever goes up.
but it doesn't work for me, when I press the Z key in any option, lower the lever and then I can't raise it

this is my object option(yes or no) and this is the code:

if keyboard_check_pressed(vk_down) and image_index = 0
{
image_index = 1; //option no
image_speed = 0;
}
if keyboard_check_pressed(vk_up) and image_index = 1
{
image_index = 0; //option yes
image_speed = 0;
}

if image_index = 0 and keyboard_check_pressed(ord("Z"))
{
with (obj_lever)
{
image_index = 1; //lower the lever
image_speed = 0;
}
instance_destroy(); //destroy the options
}

if image_index = 1 and keyboard_check_pressed(ord("Z"))
{
with (obj_lever)
{
image_index = 0; //raise the lever
image_speed = 0;
}
instance_destroy(); //destroy the options
}
 

TheouAegis

Member
Actually I just re-read your code and you don't need else, because you are destroying the options.

Your lever shouldn't be animating at all, you set its image speed to 0. So I would suspect that you have code somewhere else which set the lever's image speed back to 1.

...
How are you creating the option object instance? Your code destroys itself, so unless you create a new instance of the options object, you're not going to be able to turn the lever off.
 
M

Matias Fernandez

Guest
thanks for answering

my problem is that the lever does not respect my condition of image_index = 0 and keyboard_check_pressed (ord ("Z"))

it goes down even if it has image_index = 1 and keyboard_check_pressed (ord ("Z"))

and when it goes down I can't upload it (although it goes up if I press many times (vk_down) and Z or at the same time

in my object lever I have programmed to create the yes or no sign if the player is close and press the Z

What I want is to be able to choose an option and that the lever is lowered or raised depending on the option chosen
 

TheouAegis

Member
What's all the code you have in the lever object? Because you're switch object doesn't appear to have anything at all that would cause the behavior you're describing.

Shouldn't your options be "Up" and "Down" instead of "Yes" and "No"? Because if it ask the player, do you want to lower it, that doesn't mean you want to raise it. If you don't want to lower it, it means you don't want to do anything at all. And if you don't want to flip it, then you don't want to do anything at all.

You could try consolidating the code.
Code:
if image_index 
    if keyboard_check_pressed(vk_up)
        image_index = 0;
else
    if keyboard_check_pressed(vk_down)
        image_index = 1;
if keyboard_check_pressed(ord('Z')) {
    obj_lever.image_index = !image_index;
    instance_destroy();
}
 
M

Matias Fernandez

Guest
I could fix it
what I did more than anything was to separate the if better because otherwise the image_index didn't take them
and also add a global variable (although it did it before but it didn't work)
in short the key was to place the ifs better

if (keyboard_check_pressed(vk_right)) and (image_index = 0)
{
image_index = 1;
image_speed = 0;
}

if (keyboard_check_pressed(vk_left)) and (image_index = 1)
{
image_index = 0;
image_speed = 0;
}
if keyboard_check_pressed(ord("Z")) and global.lever = true
{
if (image_index = 0)
with(obj_lever)
{
image_index = 1;
image_speed = 0;
}
global.lever = false;
}
if (image_index = 1)
{
with(obj_lever)
{
image_index = 0;
image_speed = 0;
}
global.lever = false;
}
 
Top