How do I compare 2 numbers to determine a sprite animation?

0 favourites
  • 4 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • Hello!

    I attached an image, so you guys can visually see what I'm trying to accomplish.

    My game is a music career simulator; for this particular context, the player selects the songwriting studio they wish to record in -- each studio has a varying level of success (i.e. the cheapest studio has a 40% success rate), and they complete the mini-game. Afterward, they are taken to this Summary Layout which'll show their score, and check if the songwriting session was successful or not.

    I have a Spin Wheel sprite, with "Yes", "No", and "Spinning" animations. The "Yes" animation will, obviously, cause the spinner to land on a "Yes" square, and vice versa.

    I thought the simplest way to accomplish this would be to set a local variable (called "Decider"), and compare against the "studioNum" value.

    //I first set Decider to a number between 1 and 100.

    On Start of Layout -> set Decider to int(random(1,100))

    //Then, I compare...

    On animation "Spinning" finished -> If studioNum <= Decider -> set animation to "Yes"; Else -> set animation to "No";

    For whatever reason, this logic doesn't work?

    I tried adding another local variable (a boolean), called "isSongSuccess". Then, I tweaked my logic...

    On Start of Layout -> set Decider to int(random(1,100))

    And added some Javascript...(along with some debugging)

    const ranNum = localVars.Decider; const studioNum = localVars.StudioNum; let isTrue = localVars.IsSongSuccess; const debugText = runtime.objects.Text_Debug.getFirstInstance(); if (studioNum <= ranNum) { isTrue = true; debugText.text = `${studioNum} < ${ranNum} ${isTrue}`; } else { isTrue = false; debugText.text = `${studioNum} < ${ranNum} ${isTrue}`;; }

    Knowing the boolean accurately displays true or false, I then tried using the boolean result to try and set the animation...

    isSongSuccess True -> set animation to "Yes"; isSongSuccess False -> set animation to "No";

    Yet still, it does not seem to work?? In the picture, you can see my debugging text at the bottom of the screenshot. The spin wheel SHOULD have played the "Yes" animation, but instead, it played the "No" animation.

    Any help would be appreciated!

  • I'm surprised you can select the local var in the second event. Usually it would be out of scope. So the local var being used here is probably set to 0 is my guess.

    Try the same logic with global variables, is it fixed ?

  • I'm surprised you can select the local var in the second event. Usually it would be out of scope. So the local var being used here is probably set to 0 is my guess.

    Try the same logic with global variables, is it fixed ?

    It was actually just an order issue, it seems. The resolution was: changing the condition from 'On Start of Layout,' to on "Spinning animation."

    The logic worked, but for whatever reason, after it would check if the song was successful, it would default back to its original value by the time the spinner started spinning. Not sure why. I didn't have any other code that changed the local variable value, soo it was a real head-stumper. But I got it fixed and working :) thanks for the reply!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So that is what I mentioned above, you are out of scope so the variable is reset. So you've now put the logic within the same event yes this should fix it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)