How do I show random image [no repeat] from array?

0 favourites
  • 8 posts
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • Hi,

    I see from other forum questions & tutorials that there are multiple ways of doing this, and that this is a core C2 skill.

    But I haven't been able to make it happen yet.

    I'm making a simple language game.

    Example of play:

    The player sees a picture of a duck and 2 words: 'Cat' and 'Duck'.

    When he clicks on the word that matches the picture, a new picture appears (let's say, a house), with 2 new words 'House' and 'Telephone'.

    What's the easiest way to stop correctly answered questions from repeating?

  • how about using booelan variable?

    if the word matches with the picture, then set booelan to true.

    then generate a new picture with false booelan.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for your reply.

    That sounds good- but I don't know how to integrate that solution with my current set up.

    I'm happy to start again- but could you elaborate a little more?

  • 1. on start of the layout, set your array to 1, 2, 3... till the number of your questions.

    2. then use function to set random number from(1-end) to show a random question.

    3. if the answer is correct, change the value to "solved"

    .

    then, to generate a new question, call the function again, but if array index-X has been solved, call the function till you find an unsolved question.

    .

    this is not the best method, but I hope you can get an enlightment from this.

    sorry for my bad english.

  • Thank you very much,

    I'll try that!

  • a little suggestion to speed up the process of item picking. After one question is completed, instead of flagging it as "solved", delete it from the array.

    This will prevent this possible case:

    Your array has 1000 items at the beginning, you completed 999 items, and now the loop might need quite long to find the last possible question to be displayed.

    When you remove the solved items entirely and just pick a random item from (0-width of array), you will always pick a valid one

  • Thank you. It'll be a few more days before I can try any of this out (I'm travelling to another country)

    But those sound like good ideas to a problem I've been avoiding for ages.

  • nice idea ubivis..

    I almost forgot that you can delete an index of array in C2

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