How do I require that a series of objects be clicked in order?

0 favourites
  • 9 posts
From the Asset Store
Magic Series FIRE Sound Pack comes with 600 high-quality sound effects
  • If I present the user with several objects and they only succeed if they click on them in a certain order (that I choose).

    Example - In the attached image the user must click on the times in sequential order. If they do they "win", if they click out of order it stops and says try again.

    I am also unclear how to accomplish this if using instances vs. separate distinct objects.

    Many thanks, I have tinkered with this for hours with no success. Any help is greatly appreciated.

  • There's several ways to achieve this.

    The most intuitive way I can think of is to give all the clickable objects an instance variable eg. listPosition. Then you could go through all the objects and set listPosition = 1 for the first one, listPosition = 2 for the second, etc.

    Then you could have two global variables eg. objectToClick (which starts at 1) and totalObjects (where you can put the total number of objects eg. 3).

    Then we can just do this (pseudo code but just to give you an idea):

    if user clicks object & object.listPosition = objectToClick : add 1 to objectToClick

    if user clicks object & object.listPosition != objectToClick : show "fail" message / fail events

    if objectToClick > totalObjects : show "success" message / win events (user has won)

    So, if they click object with listPosition=1 and objectToClick=1, the game allows them to go on to click object with listPosition=2, etc - and if they click anything else they get the fail condition.

    An alternative way to do this would be to match two text lists, but that may involve mucking about with string operators and might be slightly more confusing? Same result anyway :)

  • Do you need to check if the sequence is correct at each click, or is the check done once at the end of the player's sequence selection?

    Anyway, reading your question, I had an idea that maybe could work, and it would avoid you to use a lot of control variables or whatever:

    When you create text isntances, do you do it using its correct order and just arrange them in random order inside the screen? If yes, you could take advantage of the UIDs or IIDs of the instances that will surely be generated in incremental order.

    So, for example, if the IID of the second instances clicked is not equal to the IID of the first instances clicked +1, then the selection sequence was not done correctly.

  • There's several ways to achieve this.

    The most intuitive way I can think of is to give all the clickable objects an instance variable eg. listPosition. Then you could go through all the objects and set listPosition = 1 for the first one, listPosition = 2 for the second, etc.

    Then you could have two global variables eg. objectToClick (which starts at 1) and totalObjects (where you can put the total number of objects eg. 3).

    Then we can just do this (pseudo code but just to give you an idea):

    if user clicks object & object.listPosition = objectToClick : add 1 to objectToClick

    if user clicks object & object.listPosition != objectToClick : show "fail" message / fail events

    if objectToClick > totalObjects : show "success" message / win events (user has won)

    So, if they click object with listPosition=1 and objectToClick=1, the game allows them to go on to click object with listPosition=2, etc - and if they click anything else they get the fail condition.

    An alternative way to do this would be to match two text lists, but that may involve mucking about with string operators and might be slightly more confusing? Same result anyway :)

    Thanks very much. So in this approach are all the objects instances or discreet objects? Seems like they have to be separate objects. If they're instances the list positions is the same for all, when I change it for one they all change.

  • Do you need to check if the sequence is correct at each click, or is the check done once at the end of the player's sequence selection?

    Anyway, reading your question, I had an idea that maybe could work, and it would avoid you to use a lot of control variables or whatever:

    When you create text isntances, do you do it using its correct order and just arrange them in random order inside the screen? If yes, you could take advantage of the UIDs or IIDs of the instances that will surely be generated in incremental order.

    So, for example, if the IID of the second instances clicked is not equal to the IID of the first instances clicked +1, then the selection sequence was not done correctly.

    I would like to learn how to do it in both cases (go all the wya through whether you're right or worng, and also get stopped as soon as you're wrong). Also the objects may not be text, they could be sprites. The IID approach is what I tried instinctively but I just couldn't get it to work. I will try what you've suggested. Thanks.

  • Thanks very much. So in this approach are all the objects instances or discreet objects? Seems like they have to be separate objects. If they're instances the list positions is the same for all, when I change it for one they all change.

    No, that's the whole point of instance variables - they can be set separately for different instances of the same object.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > Thanks very much. So in this approach are all the objects instances or discreet objects? Seems like they have to be separate objects. If they're instances the list positions is the same for all, when I change it for one they all change.

    No, that's the whole point of instance variables - they can be set separately for different instances of the same object.

    Hi Mike, I have it working except for the failing part, if you have a chance to take a look at the c3p. It fails every time, even you win, if that makes any sense. Many thanks. shorturl.at/gvI13

  • Hi ,

    the download link you posted is not working.

    I created a simple example for you following the advice mikehive gave you.

    I created it very quickly, but I hope it can help you understand how to solve your problem. If you like to experiment and try other solutions, please create an example project and we will correct it together.^^

    https://www.filemail.com/d/omvzgpjbnsifzlj

  • Thanks Biscotto, this is very helpful. I like the use of else and the loop index and creation cycle. Those are all techniques I am not familiar with so it's exciting to learn something new.

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