Simple Array Shuffle Question?

0 favourites
From the Asset Store
Simple but fun word game. Restore an original word from shuffled letters.
  • Hi guys, me again. Happy New Year to everybody.

    Thing is, I want to make the array (which is imported from JSON) to random. Means every time I restart the layout or click a button the array value should be shuffled.

    I tried this way, but couldn't succeed.

    Please check this dropbox.com/s/kmns0c2u8g84rwf/Array%20Shuffle%20Exp.c3p

  • Try this:

    .

  • Thanks, dop2000 bro, that was amazing.

    Two quick questions.

    Question 1. In another scenario, I have an array of a certain height and width and data on it. How can I replace an index of the array? eg. Value of index 1 is "1" when Player collide with an object or by clicking a button I want set it something else, for eg. "23".

    I don't want something like this. (Via)

    Because my array would contain mostly numbers, the same value might be repeated on several indexes.

    Question 2

    How to make the addition of all the value from the array.

    eg.

    How do I calculate all the array value and store in on a global variable? For example here if we add all the numbers the value would be 20.

  • 1. I don't understand the problem. If you know the index you want to change, then simply do "Array set value at index ..."

    2. You need to run "Array for each element" loop and add all values to a variable.

    Array for each element
     Add Array.CurValue to TotalVar
    
  • 1. Actually I tried it

      + Button: On clicked -> Array: Set value at MyArray.At(2) to 12909090

    but it doesn't reflect, I dunno what I'm doing wrong.

    2. That works, but if my array consists of 5,5,5,5 value, once I hit the button it shows 20, but if the user hit it twice it makes it 40, 60, 80 etc the same issue happen with on the start of the layout If I put it on the start of the layout, every time the layout restart the value of is keep doubleing.

  • here the c3p

  • 1.

    Array Set value at 2 to 12909090

    2.

    If you want to calculate the total again, you need to reset the variable to 0 first.

  • Thank you Thank you.

  • Hi, Dop, The logic you gave me to random the array work just awesome. Just one question, When it shuffle, can we avoid the blank cell?

    For eg.

    I have made a mathc game, where user will mathc pictures corresponding to its text. I have made one JSON array to have all the texts.

    But when I shuffle the array, sometimes, I'm getting blank text, it is obvious because the array have those blank cells. Is there anyway to avoid those blank cell while shuffle it?

  • The logic I gave you was for a 1D array, but you have a 2D array on your screenshot. I don't quite understand how you want to shuffle it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My bad, You are correct, that logic won't support or applicable here.

    I have attached C3P project, please check.

    Please help me how can i achieve this using one JSON file?

  • I have multiple layouts, One For Numbers, One For Colors, One Alphabet, I have multiple Animation inside a single sprite called "PICTURE_SET" sprite. If i use separate JSON file for each animation set then the code becomes error-prone. If I can able to Shuffle the 2D array and avoid those empty cell, then it can be done using just a single JSON array. or Am I missing something here? is there any better way to accomplish what I'm trying to achieve?

  • Here another C3p, this is what I trying to achieve. Please check.

  • I don't understand what you are trying to achieve, even with the project file.

    Can you explain?

    If you need to shuffle 2D array, can you post two pictures - the original array and shuffled (manually, just as an example)?

  • I'm trying to make this matching game as an endless one, Every time when the user restarts the layout I want the user to have a different set of images.

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