[Solved] How do I add a random value to a specific variable

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello !

    I am trying to add a random value to a variable. Let me explain more clearly.

    I have a variable " Value " on a sprite, which has to get a random value at the loading of the layout.

    There is where am i at the moment :

    So, it choose an ID between 1 and 8 (there is 8 occurrence). Then it applies to this specific one, one of the value in the choose. From there everything is working.

    My problem is, I need 2 things :

    • A loop (but never used it, so i don't know which one and how to configure it) so I can apply it to every occurrences.
    • Something to put no duplication into it because each value (top ...) as to be attribuate only ONCE (and this is very important).

    After that, I have to do this with an other loop to apply to 8 new occurence (black and white ones) and this one has to have some values multiple times and i'm lost aswell.

    Any helps is welcome!

    Regards.

  • Well i found the loop, I'll just use the for each instance, which works perflectly and it's easy.

    But I still have the problem about the choose, if only a "choose once" could exist haha

  • It's not really what I'm looking for.

    I have a list with height directions that I need to attribute to the variable "Value" for each pieces of my sprite, but the problem is I need to attriburte the direction only 1 time

  • It is exactly what you look for. (if i understand what you want)

    Populate the array with the 8 directions. Give the sprites an instance variable 'direction' (text)

    I suppose you have 8 Sprites.

    For each 'sprite'

    ................... sprite > set instance variable 'direction' to BHTSmartRandom.Next

    They all have now a random chosen non repetitive direction. No idea why you need to distribute with a value.

  • Oh yeah, way easier with the way you explain it.

    Just a question about this, I want to access to the string, not the number. But when I look in the debugger I see a number, not the real value (like "top").

    Just like the screens shows :

  • Set Direction to directions.At(BHTSmartRandom.Next)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh ! Thank you, works perfectly <3

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