How do I set the value of an array to randomise a text file and have no repeats?

0 favourites
  • 8 posts
From the Asset Store
Easy to use shop and inventroy populated by an array!
  • I'm creating a quiz game and I need the questions to appear in random order and not repeat. I followed a tutorial on YouTube and the values appear randomly but so far they're just numbers. I have the questions in a text file, so I need to use this to populate the array but how do I do this? So far, the equation I've used - tokenat(AJAX.LastData,i,"|") only shows the questions in ascending order, not randomly. (For your reference, 'i' is a local variable and '|' is the separator in my questions file.

    I've been stuck on this about 2 weeks and no matter what I've tried it hasn't worked, so any advice would be amazing.

    I've attached an image of my events and actions - hopefully, this makes it clear to see where I'm going wrong.

  • Already answered when you posted it last time. You need a permutation table and loop through the index of this for the shuffle instead of random.

  • Are you able to show me how this is done in events and actions? I tried so many ways before using the permutation table and couldn't get it to work properly.

    Sorry, I'm still new to using Construct and have no previous background of game dev.

  • Made a small file dropbox.com/s/lebmbfijnr57r3t/shufflearray.c3p

    There are two arrays that represent the initial one and then the shuffled one with no repeats

  • Wow! Thanks so much Lionz - I really appreciate your help.

    I'm almost there with it now but have a couple of questions:

    1. How do I pull the questions like you have done? I have 50 of them and they're stored in a text file. I am familiar setting at X of an array but have never used the 'pull' action like you have. I can't figure out how to populate the array using this method.

    2. I then tried setting at X of the array (as I'm familiar with this) and managed to populate it using a for loop and local variable number but when setting at X of the shuffled array using the formula given in your example - QuestionsArray.At(AdvancedRandom.Permutation(loopindex)), it randomised the order but there are quite a few empty gaps in the shuffled array, any idea why this could be?

  • Looks like you are populating the first and second array in the same loop, I wouldn't do that. You need the first array ready first and you can view it in debug view to ensure it's correct. The reason you have gaps is because some rows don't exist yet. First populate an initial array then when that's complete start the shuffle loop.

    For question 1, that's not a problem your method of populating the array is fine when using an external file, my method was a quick way of adding some data to the array when I don't have an external file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks so much for your help Lionz! I'VE DONE IT!!!

    Can't tell you how grateful I am for that, really appreciate it as I've been stuck on this for so long.

    This is how I've done it:

  • Great :)

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