• 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 Scripts getting called but not doing what they are supposed to do

H

Hyteel

Guest
Hi, I am working on an animation-system and have a very small amount of code related to it currently. But I have managed to come across a very unusual problem. My code (Client):

GML:
//Animation

CurrentAnimationFrame += 1;
var ReturnedValue = scAnimationHandler(CurrentAnimation, CurrentAnimationFrame);
if (ReturnedValue == 0)
    {
    image_index = ReturnedValue;
    CurrentAnimationFrame = 0
    }
else
    {
    image_index = ReturnedValue;
    }
and (scAnimationHandler) :

GML:
//Inputs
Animation = argument0;
AnimationFrame = argument1;

//Outputs
//Idle
if (Animation = 0)
    {
    return 0;
    }


//Walkinganimation [Upper]
if (Animation = 1)
    {
    if (AnimationFrame == 1)
        {
        return 1;
        }
    else if (AnimationFrame == 2)
        {
        return 2;
        }
    else if (AnimationFrame == 3)
        {
        return 3;
        }
    else if (AnimationFrame > 3)
        {
        AnimationFrame = 1
        return 1;
        }
    }
If I do any keyboard input CurrentAnimation becomes 1.
Everything works properly if I tap the keys, ie. AnimationFrame changes to 1 after going above 3
But if I hold down a key, even though the script is called, AnimationFrame goes above 3 (show_debug_message(Animation) in Script)
I am almost 100% certain it has nothing to do with the code controlling movement and it is 230 lines of code long so pasting it here would just cause more harm than good. Thanks for taking your time to read this!
 

Nidoking

Member
Monster Edit: Strike everything I said. When you set AnimationFrame = 1, you're not setting the value of CurrentAnimationFrame. You're just setting the value of the variable within the function. That's why CurrentAnimationFrame is not resetting unless you set Animation to 0, in which case, the function returns 0 and you get the reset.
 
Last edited:
H

Hyteel

Guest
When the script is ran and malfunctions CurrentAnimation (show_debug_message(Animation)) is 1
 

chamaeleon

Member
Seems terribly easy to insert a show_debug_message() statement in every if code block with relevant variables displayed and generate a trace of what code path is taken, and then analyse after a run.
 
H

Hyteel

Guest
it is what I have done, and I trace it to the script part. Even though Animation = 1, and AnimationFrame > 3, it will not change to 1 again.
 
H

Hyteel

Guest
Monster Edit: Strike everything I said. When you set AnimationFrame = 1, you're not setting the value of CurrentAnimationFrame. You're just setting the value of the variable within the function. That's why CurrentAnimationFrame is not resetting unless you set Animation to 0, in which case, the function returns 0 and you get the reset.
Thank you so much! that was the reason it did not work.
 
Top