Problems to verify if the same number was clicked

0 favourites
  • 10 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • I'm having some trouble to find the error of this script and so I decide to ask for help. The goal of the script is to check that the correct number was clicked. When picks a number, the audio tells the same number and I click on the same number, but the answer appears as wrong. Someone could check for me? Thank you.

  • Is numbers.value a text variable?

  • ramones,

    number.value is a number variable

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • RenatoB, there are a few things in your code that seem a little funny to me, but I tested some of them out and they seem to work (but just aren't quite the way I would have done it).

    I believe the main problem is that the CheckAnswer function is not working with the same "numbers" instance as the one you touch. When you touch one, it is the only instance "picked", but when you call the CheckAnswer function it will randomly pick any instance to work with. So, You should pass in the numbers.UID into the CheckAnswer function, and then in there "pick" that unique ID.

    One other potential problem is in your "On Start of layout" section, where you "Pick a random numbers instance". You repeat that loop 20 times, but theoretically it could pick the same numbers instance all 20 times. Out of 20 times through the loop, you will have no way of knowing how many instances got picked more than once, and how many never got picked. If you have 20 instances of numbers, and want to set each one to a random animation frame, then replace the "Repeat count times" and "Pick a random instance" with "For each numbers". (the part where you choose a random index and delete it out of the array seems fine as far as I can tell).

  • RenatoB, there are a few things in your code that seem a little funny to me, but I tested some of them out and they seem to work (but just aren't quite the way I would have done it).

    I'm a newbie programmer trying to accomplish some personal projects. When I compare my scripts with others that were written by more experienced programmers, I see that are very different. But how in the end everything works, I keep following this line.

    I believe the main problem is that the CheckAnswer function is not working with the same "numbers" instance as the one you touch. When you touch one, it is the only instance "picked", but when you call the CheckAnswer function it will randomly pick any instance to work with. So, You should pass in the numbers.UID into the CheckAnswer function, and then in there "pick" that unique ID.

    I'll check it. What I find strange is that the texts fields that I include for testing, shows the same number in both: the number of the draw as well as what was clicked. I thought it was something wrong, the text fields would show that.

    One other potential problem is in your "On Start of layout" section, where you "Pick a random numbers instance". You repeat that loop 20 times, but theoretically it could pick the same numbers instance all 20 times. Out of 20 times through the loop, you will have no way of knowing how many instances got picked more than once, and how many never got picked. If you have 20 instances of numbers, and want to set each one to a random animation frame, then replace the "Repeat count times" and "Pick a random instance" with "For each numbers". (the part where you choose a random index and delete it out of the array seems fine as far as I can tell).

    In fact the numbers are not repeated, only the "0" but it's intentional.

  • ramones,

    number.value is a number variable

    Well you're comparing soundNumber (a text variable) to number.value (a number variable) in events 12/13. You'd need to compare similar types either by making both variables text or number, or by comparing

    soundNumber = str(number.value)

    or

    int(soundNumber) = number.value
  • Hi After I read your post I changed the soundNumber variable type to number too. Now both variables are number variables. I even created a local variable with the same name and removed the global one, but still not working. Now the problem inverted: all number that I clicked is right.

  • Instead of trying to solve the problem I decided to follow the AllanR suggestion and made comparisons between UIDs and everything worked. Thank you for help me.

  • RenatoB, the reason you were seeing the correct number when you clicked on it was because you were displaying the number in the text field before you called the CheckAnswer. At that point you did have the correct instance, but then in the function it has no idea what has happened outside of the function so it just used any random instance.

    The comparing a string variable to an integer would have also been a problem... anyway, glad you got it working!   :)

  • allan: I got it. Living and learning. Thanks for the tips.

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