Random randomness

Get help using Construct 2

Post » Sun May 20, 2012 6:54 pm

can anybody help me i cant understand why this wont work?

im trying to get the police sprite to spawn when the letters deliverd variable reaches a random number between 1 and 6

have a look its pretty obvious what im trying to do.

exampledarksteeldanger2012-05-20 19:02:43
B
10
S
1
G
1
Posts: 74
Reputation: 1,637

Post » Sun May 20, 2012 7:21 pm

change random(7) to int(random(7)) so only whole numbers are used 0,1,2,3...
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Sun May 20, 2012 7:23 pm

thankyou
B
10
S
1
G
1
Posts: 74
Reputation: 1,637

Post » Sun May 20, 2012 7:24 pm

EDIT: Great... R0j0 beat me to the punch... Anyway this is a different way of doing it.

Is this what you're after?

Keep in mind this doesn't take into account if a policeman is already at the house... That's a bit more complex.sqiddster2012-05-20 19:24:55
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sun May 20, 2012 7:35 pm

for some reason when i use int(random()) the police man appears at the begging of the layout, thats not what im after i want him only to spawn when the random number has been reached?
B
10
S
1
G
1
Posts: 74
Reputation: 1,637

Post » Sun May 20, 2012 7:38 pm

@sqiddster

yeah that would work but im just trying to understand how the random() function works, yours is more advanced than i need it to be.....but thats probably the way to go
B
10
S
1
G
1
Posts: 74
Reputation: 1,637

Post » Sun May 20, 2012 7:52 pm

Yeah, the random() function is a bit tricky with its upper and lower bounds. Keep in mind you have floor() and ceil(), which will either truncate, or truncate and add one.
Here's what you get from int, floor, and ceil:
ceil(5.6) gives 6
floor(5.6) gives 5
int(5.6) gives 5

That's right, the int function does not round.

Keep this all in mind, and in some cases, consider using the choose() function to randomly choose between a fixed set of parameters.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sun May 20, 2012 8:04 pm

can i do choose(random()) its telling me something about parameters

i thought seeing as the letters variable was a definite number 1,2,3 etc
the random() function would be able to choose a number between the parameters you can set with equal to (the random number)

i think that makes sense, its been a long day
B
10
S
1
G
1
Posts: 74
Reputation: 1,637

Post » Sun May 20, 2012 8:55 pm

ive looked at it again and this should work but alas it does not

when i run it without using int(random()) and just put in a number, it works? bizarre, ive checked the relevant tutorial and this is what it tells me to do..........

where am i going wrong?


example 2
B
10
S
1
G
1
Posts: 74
Reputation: 1,637

Post » Sun May 20, 2012 9:14 pm

Your capx is messed up as it is not choosing a random house... You are doing something about letters.
Maybe it would be better if you told us exactly what you want to accomplish.
If you want him to appear at a random house, use the capx I sent you. What about mine isn't working for you?
To choose from a set of parameters, use the choose() function.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Next

Return to How do I....?

Who is online

Users browsing this forum: Justin1967, qaisarehman and 33 guests