Random between 10 number using array

0 favourites
  • 3 posts
From the Asset Store
80 pieces of loopable game music, 10 game overs and 10 level complete pieces.
  • Hello, I have a Question.

    I want to make a button with a random between 1 and 10 number then store the result in an array. Then I click again the button and get a new random without the number that . this give me a new number that I want to store in the array too. I click again the button again with a random that will not include the both first two numbers (that are stored in the array) to the random results. I want to repeat this operation until I only have one number.

    I know the theory to do this but I don?t know how to write and use correctly the arrays for do it. Please if any one have some .capx example or some clear explanation of this answer my question. Thanks <img src="smileys/smiley1.gif" border="0" align="middle" /> <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Without testing and warranty, but basically this should work:

    Create two one-dimensional arrays and a variable 'myrandom'. Fill the first one with the numbers 1 to 10. On button click get one number from the first array with

    set myrandom to floor(random(array1.Width))

    array2.Push front array1.at(myrandom)

    array1.Delete myrandom

    Do this until array1.Width = 1. Then the first array contains one number and array2 the other nine.

  • Try Construct 3

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

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

    OK, this works but not exactly in the way that I would like.

    There is the example.

    TestArray1

    The problem is that when I push the button with random numbers from array1, sometimes the number that is throws the random is repeated. I'm doing something wrong but I don't get it yet. If somebody can help me!

    Thanks

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