How do I choose random image by rarity

Get help using Construct 2

Post » Thu Mar 24, 2016 10:32 pm

Hello all :)

i need a simple project: in a window, i've only 1 sprite, with 10 images
every sprite must have a rarity (common, un-common-rare)
when i click on image, sprite must change to other one by rarity
sprite have:
image 0 common
image 1 common
image 2 common
image 3 common
image 4 common
image 5 un-common
image 6 un-common
image 7 un-common
image 8 rare
image 9 rare

some ideas?
thanks
B
8
S
1
Posts: 17
Reputation: 503

Post » Thu Mar 24, 2016 10:56 pm

I am really not clear on what you are trying to do and there is no probably many different ways to achieve whatever you are trying to do.

Which of the following have you thought about using to implement this:
Instance variables
Different sprites vs different animations
Families
Array

I would make 3 different sprites, one for each level of rareness, put all the cards in as a different frame in the same animation. Then have it randomly choose a frame on prompt.

Have you tried anything yet?
ImageImageImage
B
44
S
26
G
11
Posts: 520
Reputation: 10,506

Post » Fri Mar 25, 2016 12:14 am

Message: Agrauwin can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
badmoodtaylor wrote:I am really not clear on what you are trying to do and there is no probably many different ways to achieve whatever you are trying to do.


hi and thanks for reply
this is an example of random: https://app.box.com/s/w938y0zspne5asrjafxm

but i dont need only "egual" random
i need that Animation Sprite frames 0 is most (?) common that Animation Sprite frames 5 (more rare)
i can use some variable, examples "rarity" with a %
totat rarity is 100%:
rarity common + rarity uncommon + rarity rare = 100%
than i can set:
rarity common= 45%
rarity uncommon= 35%
rarity rare= 20%

so, onload my Animation Sprite Frames will be a random: 0 to 5 according with variable "rarity"
every time i click on my sprite, rarity check
and will display one Animation Sprite Frames 0 to 5 according with variable "rarity"

i decide rarity for every sprite: how i can give the variable rarity to my Animation Sprite Frames?

example i want:
0 set to common
1 set to common
2 set to common
3 set to uncommon
4 set to uncommon
5 set to rare
B
8
S
1
Posts: 17
Reputation: 503

Post » Fri Mar 25, 2016 12:24 am

you can try:
Var = floor(random(0,101))
if Var <=35
animation frame = choose (0,1,2)
else
if Var>35 | Var <=80
animation frame = choose(3,4)
else
animation frame = 5
Image Image
B
26
S
15
G
143
Posts: 881
Reputation: 74,560

Post » Fri Mar 25, 2016 12:44 am

Oh, you are saying you want some to be more rarely chosen than others? Let's say like cards in a deck (like in a board game/collecting game, not poker cards) where there are more of some cards than others.

If so I think @MadSpy hit the nail on the head there (except I think flipflopped percentages, 35 should be 45).

Are you familiar with random and choose, the expressions for generating random numbers? (shown by MadSpy above). That is all you need to create any type of randomness you want. After learning about those you just have to really think out how you want the math because you could do it tons of different ways.

For example, here is one thing to think about:
You say you want a common card drawn 45% of the time, uncommon, 35% of the time, and rare 20% of the time. MadSpy's example will do exactly what you want.

That means the following probability of drawing each card:
0: 15% (45/3)
1: 15%
2: 15%
3: 17.5% (35/2)
4: 17.5%
5: 20% (20/1)

So probability wise you will draw common cards most often but the rare card, since you only have one rare card, will be the most commonly drawn card in the game. Not sure you are indenting that . . .

But that is more of a balancing discussion. Like I said, you could set this up so many different ways so what I suggest is you get out pen and paper and write out the math you want. That way you can ask specific questions on how to implement if you get stuck.
ImageImageImage
B
44
S
26
G
11
Posts: 520
Reputation: 10,506

Post » Fri Mar 25, 2016 9:15 am

MadSpy wrote:you can try:


thanks! you hit the point!!!
;)
B
8
S
1
Posts: 17
Reputation: 503

Post » Fri Mar 25, 2016 9:17 am

badmoodtaylor wrote:Let's say like cards in a deck (like in a board game/collecting game, not poker cards) where there are more of some cards than others


;) yes is that!
thanks for helping
B
8
S
1
Posts: 17
Reputation: 503

Post » Fri Mar 25, 2016 10:30 am

See this tutorial on monster loot drop.
It actually explains how to do probabilities and rarity in the way you are looking to achieve.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306


Return to How do I....?

Who is online

Users browsing this forum: dop2000, R0J0hound and 11 guests