• 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!

Issue with button

B

Branden Skidmore

Guest
So I'm trying to make a button like how it is in undertale or the older zelda games.
Whenever I run the game in the Compile Errors it says
Object: obj_buttonA Event: Step at line 7 : malformed if statement

My code is below

Code:
image_speed = 0

if place_meeting(209,55,Frisk) {
      image_index = 1
}

if (image_index = 0); {
  audio_play_sound(snd_button_press,1,false)

if (image_index = 1) {
     audio_stop_sound(snd_button_press)
     }
}
 
You have a semicolon on the "image_index = 0" line (funny enough, it' the only usage of it in the entire code block and it's in the wrong spot :p). I also recommend using two equal signs for comparison, in case compatibility changes in the future.
 
N

NeonBits

Guest
I don't know if I'm mistaking, as it seems to be possible to check for collision in the same non collision block, but would this run inside an "image_index == 0"?
Code:
if (image_index == 1)
{
     audio_stop_sound(snd_button_press);
}
 
B

Branden Skidmore

Guest
I don't know if I'm mistaking, as it seems to be possible to check for collision in the same non collision block, but would this run inside an "image_index == 0"?
Code:
if (image_index == 1)
{
     audio_stop_sound(snd_button_press);
}
Tbh I don't know because I just found out that image index 0 isn't a thing and I don't know what the first frame of the sprite would be called
 
N

NeonBits

Guest
I think (image_index == 0) makes sense... in 1.4, I had to change for 2, which is the third frame, and result is correct.
 
B

Branden Skidmore

Guest
image_index == 0 is definately a thing, it's the first frame of your sprite. Their index start at 0, not 1
I had to change my code up and it still won't detect image_index == 0
It just stops at that bit
 
T

Taddio

Guest
Try something like
if(image_index==0){
show_debug_message("Sprite frame = 0");
}
I'm pretty sure it would confirm that it does point to your frame number.
I suspect the problem comes from elsewhere.
Did you removed the semicolons in your if statement, added them after your lines that sets variables and used == instead of = for your comparaisons? (Just to be sure it's not a syntax thing for some reasons)
 
B

Branden Skidmore

Guest
Try something like
if(image_index==0){
show_debug_message("Sprite frame = 0");
}
I'm pretty sure it would confirm that it does point to your frame number.
I suspect the problem comes from elsewhere.
Did you removed the semicolons in your if statement, added them after your lines that sets variables and used == instead of = for your comparaisons? (Just to be sure it's not a syntax thing for some reasons)
Idk but here is my new code if it helps explain it
Code:
image_speed = 0;

if place_meeting(209,55,Frisk) {
if (image_index == 0)
audio_play_sound(snd_button_press,1,false)
image_index = 1;
 }
}
 
T

Taddio

Guest
You're missing a bracket after if(image_index==0)
That's probably it...
...you're also missing a semicolon after audio_play_sound();
That's a no-no!! ;)

You could also just do
Code:
if((place_meeting(......)) && (image_index == 0)) {
audio_play_sound(snd_button_press,1,false); //with semicolon
image_index = 1;
}
Edit: there is no need to set your image_speed to 0 every step, just set in in create event and be done with it!
 
Last edited by a moderator:
B

Branden Skidmore

Guest
You're missing a bracket after if(image_index==0)
That's probably it...
...you're also missing a semicolon after audio_play_sound();
That's a no-no!! ;)

You could also just do
Code:
if((place_meeting(......)) && (image_index == 0)) {
audio_play_sound(snd_button_press,1,false); //with semicolon
image_index = 1;
}
Edit: there is no need to set your image_speed to 0 every step, just set in in create event and be done with it!
I managed to fix it. But thank you anyway :)
I could always use that code for other stuff for some diversity!
 
Last edited by a moderator:
Top