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

Get help using Construct 2

Post » Tue Jan 24, 2017 6:54 pm

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 :
Image

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.
Last edited by dreaa on Tue Jan 24, 2017 11:08 pm, edited 1 time in total.
B
5
Posts: 30
Reputation: 291

Post » Tue Jan 24, 2017 6:59 pm

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 :D
B
5
Posts: 30
Reputation: 291

Post » Tue Jan 24, 2017 7:07 pm

ImageImageImage
B
71
S
21
G
222
Posts: 3,652
Reputation: 124,733

Post » Tue Jan 24, 2017 9:09 pm

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
B
5
Posts: 30
Reputation: 291

Post » Tue Jan 24, 2017 10:14 pm

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.
B
33
S
18
G
28
Posts: 2,477
Reputation: 20,918

Post » Tue Jan 24, 2017 10:48 pm

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 :
Image
B
5
Posts: 30
Reputation: 291

Post » Tue Jan 24, 2017 10:51 pm

Set Direction to directions.At(BHTSmartRandom.Next)
ImageImageImage
B
71
S
21
G
222
Posts: 3,652
Reputation: 124,733

Post » Tue Jan 24, 2017 11:08 pm

Oh ! Thank you, works perfectly <3
B
5
Posts: 30
Reputation: 291


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests