GameMaker: Studio

GameMaker: Studio

View Stats:
atksolotl Oct 3, 2013 @ 4:43pm
Is the "not equal to" function broken? Help? :/
I've been trying for ages to get my death animation to work... All I'm trying to get it to do is start from the beginning, then destroy the object at the end.

Here is the code I have so far:
if (death) = 1
{
if sprite_index=hero_death
{
image_speed = 0.1;
}
else if sprite_index!=hero_death
{
image_index = 0;
}
sprite_index = hero_death;
}

The "death" variable is just a variable I use for when the character is dead - fairly self explanitory. And "hero_death" is the sprite animation.

Any help guys? :L This is really silly because I've been using Game Maker for a long time now... But I just can't seem to get this bloody thing to work.

The problem lies with the "if sprite_index!=hero_death" because the != doesn't seem to be registering as "does not equal"... It's odd.
Last edited by atksolotl; Oct 3, 2013 @ 4:43pm
< >
Showing 1-7 of 7 comments
Sera Oct 3, 2013 @ 8:31pm 
In my experience setting the sprite_index resets the image number to zero. Regardless, even from a raw logic standpoint it would make more sense to set the sprite_index under the condition it isn't what you want, meaning here that you slap it under the same brackets as where you set the image_index to 0.

In the event you have it setting the sprite_index every single frame for a reason (ie. defaulting to a standing sprite), then that almost guarantees your image number is resetting every frame, because, again, sprite_index is almost certainly the culprit in why you're not seeing any animation here. Essentially, you want to change your animation the instant you want it changed, and nothing more.

In any case, if you're bent on proving whether or not != is being your friend, create some variable, set it to a number, and check if it doesn't match some other number and have it change your image_blend into blue or something silly.
atksolotl Oct 4, 2013 @ 1:56am 
Originally posted by Zaron X:
In my experience setting the sprite_index resets the image number to zero. Regardless, even from a raw logic standpoint it would make more sense to set the sprite_index under the condition it isn't what you want, meaning here that you slap it under the same brackets as where you set the image_index to 0.

In the event you have it setting the sprite_index every single frame for a reason (ie. defaulting to a standing sprite), then that almost guarantees your image number is resetting every frame, because, again, sprite_index is almost certainly the culprit in why you're not seeing any animation here. Essentially, you want to change your animation the instant you want it changed, and nothing more.

In any case, if you're bent on proving whether or not != is being your friend, create some variable, set it to a number, and check if it doesn't match some other number and have it change your image_blend into blue or something silly.

Thanks for the reply, however I can see the animation - it just starts from the same frame that the running or idle animation is, and so sometimes you only see 2 or 3 frames if you happen to die at the end of the cycle.

I tried if != does not work with the way you suggested, and it worked... Although whenever I add it to sprite_index, it doesn't seem to lol.
TheNocturne Oct 4, 2013 @ 9:33am 
Your code is flawed... If the variable is equal to a value do something ELSE. And at this point you have another "if" to see if it's not equal to the value. It's OBVIOUSLY not equal to the value of the "else" part of the original "if" runs. So:

if death
{
if sprite_index=hero_death
{
image_speed = 0.1;
}
else
{
sprite_index = hero_death;
image_index = 0;
}
}
atksolotl Oct 4, 2013 @ 9:40am 
Originally posted by TheNocturne:
Your code is flawed... If the variable is equal to a value do something ELSE. And at this point you have another "if" to see if it's not equal to the value. It's OBVIOUSLY not equal to the value of the "else" part of the original "if" runs. So:

if death
{
if sprite_index=hero_death
{
image_speed = 0.1;
}
else
{
sprite_index = hero_death;
image_index = 0;
}
}

Hey man, thanks for the reply. As soon as I saw that, I felt so silly... But I just tried it, and it just freeze's the animation (it remains on image_index 0).

This is another problem I've been stuck with. Almost any other combo just freeze it. It's really strange, because it doesn't happen with my grenade animation for example - only with the main character.
Sera Oct 4, 2013 @ 10:30am 
Again, are you changing the sprite index in any given step in the code before this point? If that's the case, you'll keep having the "else" branch trigger. Alternatively, if something dabbles with your death variable, that'll skip the whole tree, but that seems a bit harder to muss up in this context.
Scarabian Oct 4, 2013 @ 10:31am 
Hi,
First to clear one point up if you check out Help>Contents>sprite_index you will see that setting the sprite index DOES NOT reset the sub image as has been guessed at in this discussion.
Secondly I do not understand why you need to overcomplicate this code with an else or a secodn if statement. this is how I have done it and it works with some temp sprites:
if (death && sprite_index!=hero_death){ sprite_index = hero_death; image_index = 0; image_speed = 0.1; }
Simply a single check to see if the hero is dead and not animated set the sprite once to the new index. Set the first animation image and start the animation. Am I missing some reason for making this piece of code more complicated. You said that you want the hero to be dead after the animation but I assume that you are doing that with an image_index check elsewhere?

One other point just to help others understand your code in future posts please use the
[/] tags in your posts around code the font is much better and easier to see the format. Another tip is to indent the code as well I find debugging correctly indented code to be much much easier. Hope this helps, Steve
Last edited by Scarabian; Oct 4, 2013 @ 10:34am
atksolotl Oct 4, 2013 @ 2:24pm 
Thank you all for your help, but I eventually figured out the problem. It seems the "sprite_index!=sprite" doesn't actually work. All other != statements do, but there seems to be some complications with the sprite_index variable... not sure why.

Eventually just did "if sprite_index = !hero_death" which seemed to work. :)

Thanks again for your help!
< >
Showing 1-7 of 7 comments
Per page: 1530 50

Date Posted: Oct 3, 2013 @ 4:43pm
Posts: 7