How do I randomize values in my array?

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hello,

    Could you please help me to randomize value in array?

    I have an array enemiesGroup, the size of which depends on location you are. And for each location there is a unique minion type. In each minion type could be up to n different minions.

    Let's say for the current location the size is 3, and the minion type is 2. There are four different minions in this minion type (1,2,3,4).

    How do I fill my array with random enemies from certain minion type?

    Thanks in advance.

    Tagged:

  • If there are not many locations then you could just run events by location, if loc=2, repeat 3 times push back of array choose(1,2,3,4). I can't see a need here to make a function that reuses the code for all locations, might as well just force it with enemy types in the 'choose'.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If there are not many locations then you could just run events by location, if loc=2, repeat 3 times push back of array choose(1,2,3,4). I can't see a need here to make a function that reuses the code for all locations, might as well just force it with enemy types in the 'choose'.

    Thank you for your answer. I don't know how to use choose expression properly. I could save minions ids in string

    loc_minions = "1,2,3,4"

    And if I use choose(loc_minions) it says I need more parameters.

  • If the enemy values must be 1,2,3,4 then use choose(1,2,3,4), 4 separate values. Or use enemy names, it might be easier.

  • If the enemy values must be 1,2,3,4 then use choose(1,2,3,4), 4 separate values. Or use enemy names, it might be easier.

    Your point is very clear. But for it, I need to manually write actions for each location.

    I want to minimize my code. For each location, I could set the variable loc_monsters which would contain a string with minions IDs. But the expression "choose" didn't work with one string.

    In my example, I need to fill my array enemiesGroup with random values from string loc_monsters. But I don't know how or is it even possible.

  • The randomness comes with using choose. I think if for each location you set a choose() with the possible enemies it is not a lot of work if you know the choices already. Also under each location comes the size, it make sense to run an event for each location.

    e.g. ...

    if location=1, repeat 3 times, push choose(enemyA,enemyB) to back of array

    if location=2, repeat 4 times, push choose(enemyA,enemyB,enemyC) to back of array

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