How do I create probability?

Get help using Construct 2

Post » Wed Feb 24, 2016 9:44 pm

Hello,

I'm building random levels generator, and I wander how can I create probability of spawning something; should I do it this way, or is it not probability: random (100), is between num A and B ( ex. 30, 70 )? I'd also would like it to change throughout the game. Any thoughts?

Thanks
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
29
G
22
Posts: 1,984
Reputation: 19,997

Post » Wed Feb 24, 2016 10:00 pm

You're on the right track. If you want to change it, use variables instead of fixed numbers in place of A and B, you can change those variables in any event.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Wed Feb 24, 2016 10:00 pm

You could do that. If it's just a probability of happening or not you could just compare with one value.
aka random(100)<40 for a 40% chance.

If you want a probability of more than two things happening you would store random(100) in a variable first. So for example you want A to have a 30% chance and B a 10% you could do:

global number rand=0

every tick
--- set rand to random(100)

rand is between 0 and 30
--- do B

rand is between 30 and 40
--- do B
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Thu Feb 25, 2016 12:19 am

Cool, thanks for clarification.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
29
G
22
Posts: 1,984
Reputation: 19,997


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Shenkai the ssj and 25 guests