How do I shuffle my data?

  • Hope everyone's having a good evening!

    I'm currently trying to:

    1. match words together from a large list of words in a sort of drag, drop and match sort of manner (but at the current moment I'm only using 6 matching pairs in a Dictionary and two pairs on the gameboard)

    2. Using an array and random command to extract this information and pin it to an object

    However instead of coming up with different words it's duplicating the first pair of words and I'm unfortunately not sure on how to change it so that every 'textMeaning' object is a different word, while also retrieving the matching 'textWord'.

    If I have to change it from a Dictionary to Array I don't mind.

    To take a look at the project so far you can find it here: drive.google.com/file/d/10nT5tc1O22xBHK45LJALKs8SmxtCC1CZ/view

    I'm sorry if this didn't make sense. ><

  • I would move it to an array with 2 columns for question and matching answer, easy to write out in a file and import to array as you did with the dictionary. Then you can pick question and answer from the same row and each time pick a random row.

  • I would move it to an array with 2 columns for question and matching answer, easy to write out in a file and import to array as you did with the dictionary. Then you can pick question and answer from the same row and each time pick a random row.

    thank you for the reply!

    I remember trying to do this method but I couldn't get the code on how to generate the matching row for the other value, if that makes sense.

    In other words, I could pick a random value from the meaning part but I didn't know how to get the matching word part, if that makes sense.

  • When you want to pick more than 1 element in a list of n elements with no repetition, you should think of a permutations table. The "Advanced Random" plugin makes it very easy to implement such a thing.

    If you have 6 matching pairs, you create a permutation table of length 6 starting at 0. It will create an array of values from 0 to 5 in a random order (basically, your indexes). You can then use AdvancedRandom.Permutation(0) to get the first random number, AdvancedRandom.Permutation(1) for the second, etc. assuring no repeating number.

    You can then use these values to index either your dictionary or array, depending on what you ended using.

  • >

    thank you for the reply!

    I remember trying to do this method but I couldn't get the code on how to generate the matching row for the other value, if that makes sense.

    In other words, I could pick a random value from the meaning part but I didn't know how to get the matching word part, if that makes sense.

    If all of the questions are at X,1 and all of the answers are at X,2, then all you need is X. So if x is 6 then the question is at 6,1 of the array and the answer is at 6,2. So the question is randomnum,1 and the matching answer is randomnum,2 every time.

  • When you want to pick more than 1 element in a list of n elements with no repetition, you should think of a permutations table. The "Advanced Random" plugin makes it very easy to implement such a thing.

    If you have 6 matching pairs, you create a permutation table of length 6 starting at 0. It will create an array of values from 0 to 5 in a random order (basically, your indexes). You can then use AdvancedRandom.Permutation(0) to get the first random number, AdvancedRandom.Permutation(1) for the second, etc. assuring no repeating number.

    You can then use these values to index either your dictionary or array, depending on what you ended using.

    Thank you for suggesting the Advanced Random plugin, I think it makes the overall randomisation of the height easier to do without mismatching the data.

    However, because I'm painfully new to this, I'm having difficulty wondering where to put the AdvancedRandom.Permutation(0).

    Like, should I add it as a function? I changed it to an array since I wanted to try the overall amount of data I have with it. I think I've already linked the Permutation with associated array.

    > >

    > thank you for the reply!

    >

    > I remember trying to do this method but I couldn't get the code on how to generate the matching row for the other value, if that makes sense.

    >

    > In other words, I could pick a random value from the meaning part but I didn't know how to get the matching word part, if that makes sense.

    If all of the questions are at X,1 and all of the answers are at X,2, then all you need is X. So if x is 6 then the question is at 6,1 of the array and the answer is at 6,2. So the question is randomnum,1 and the matching answer is randomnum,2 every time.

    Thank you for this! I think this gave me a fair idea of how I should be approaching it overall. :)

  • AdvancedRandom.Permutation(0) gives you your first random index. So let's say you need to get values from an array, you'd use something like Array.At(AdvancedRandom.Permutation(0), 0).

  • AdvancedRandom.Permutation(0) gives you your first random index. So let's say you need to get values from an array, you'd use something like Array.At(AdvancedRandom.Permutation(0), 0).

    Thank you for the suggestion! But unfortunately it doesn't seem to be working. ><

    When I try to use this the value seems to come out as 0. :(

    This is what the layout currently looks like if it helps:

  • It seems you are using height for your expanding axis, so in that case, you should be using the permutation table value on the Y axis.

    Also, shuffling the permutation table as soon as it is created is pointless, as it is already randomized on creation.

    Keep in mind that using AdvancedRandom.Permutation(0) will always give you the first index. You should probably be using a variable (instead of 0) to keep track of which permutation you are currently using.

    If you share your c3p with a broad description of what you are trying to do, I might be able to help you further.

  • It seems you are using height for your expanding axis, so in that case, you should be using the permutation table value on the Y axis.

    Also, shuffling the permutation table as soon as it is created is pointless, as it is already randomized on creation.

    Keep in mind that using AdvancedRandom.Permutation(0) will always give you the first index. You should probably be using a variable (instead of 0) to keep track of which permutation you are currently using.

    If you share your c3p with a broad description of what you are trying to do, I might be able to help you further.

    I see. I kind of had a feeling that I would need to use a variable but since I'm new to coding in general and I really can't find anything on what I'm trying to do, trying to figure it out has been really difficult. ^^"

    Overall I want the game to match the words with each other as the basis of the game, but pick the words by random from an array (or dictionary).

    So for one game they may need to pull 15 random pairs from a list of 650 or 2000 word pairs or so. This is mainly the function of the game that I'm finding the most difficult to recreate.

    The project can be found here: drive.google.com/file/d/10nT5tc1O22xBHK45LJALKs8SmxtCC1CZ/view

    If you're able to figure this out I would honestly be soooo thankful to you because this is *always* the part I get stuck on coding for this project. T_T

  • I'm not sure I understood exactly what you were trying to do, but here's my take.

    drive.google.com/file/d/1Om-Qr8qDfzjRqzDde0NpOvgG-iIgliSp/view

    I load the array from the JSON, and pick 4 pairs of x-index 0 and 2 from the 653 possibilities. I load x-index 0 as "word" and x-index 2 as "meaning". Those get shuffled randomly, left side for "word", right side for "meaning". You have to match each "word" with its "meaning" to get points.

    Note that you can't create multiple permutation tables at once, so I had to store some in arrays (namely, slots for "word" and slots for "meaning").

  • I'm not sure I understood exactly what you were trying to do, but here's my take.

    https://drive.google.com/file/d/1Om-Qr8qDfzjRqzDde0NpOvgG-iIgliSp/view?usp=sharing

    I load the array from the JSON, and pick 4 pairs of x-index 0 and 2 from the 653 possibilities. I load x-index 0 as "word" and x-index 2 as "meaning". Those get shuffled randomly, left side for "word", right side for "meaning". You have to match each "word" with its "meaning" to get points.

    Note that you can't create multiple permutation tables at once, so I had to store some in arrays (namely, slots for "word" and slots for "meaning").

    THIS IS EXACTLY WHAT I'M LOOKING FOR THANK YOU SOOO MUCH T____T

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Magistross, thanks for the information on advanced random permutation tables. This helped me out a lot.

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