on object destroyed system set varto rand(1,3) doesnt work?

Just started using Construct 2? Post your questions here

Post » Tue Oct 14, 2014 6:49 pm

Hey guys,

the following script leaves the variable completly empty:
bug.PNG

am i doing something wrong?

regards
joschi
You do not have the required permissions to view the files attached to this post.
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Tue Oct 14, 2014 9:53 pm

to answer my own question, round(random(1,3)) does the trick :D
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Wed Oct 15, 2014 5:16 am

Good for you That's the way to do it
B
257
S
43
G
15
Posts: 1,992
Reputation: 41,535

Post » Wed Oct 15, 2014 10:38 am

To further your answer.
The variable was probably not empty when not rounding it but something big like, for example, "1.13548341583454132138534436415438" (a random float number).

If your text object is not wide enough, it won't display the text and appear as "empty", when it actually isn't.
Rounding the number makes sure it's either 1, 2 or 3 and so will be displayed.
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

Post » Sat Oct 18, 2014 2:50 pm

Problem with the rounding in my opinion is that the chance of it being 2 is now 2 times as big as it being 1 or three

1 -> 1.49 = 1
1.5 -> 2.49 = 2
2.5 -> 3 = 3

When there are only three random numbers I'd rather use choose(1,2,3) , another way would be to use floor(1,3.99) or something similar..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 18, 2014 2:56 pm

int(random(1,4)) works.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Sat Oct 18, 2014 3:02 pm

Double or nothing?
Last edited by LittleStain on Sat Oct 18, 2014 3:04 pm, edited 1 time in total.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 18, 2014 3:03 pm

blackhornet wrote:int(random(1,4)) works.


(or) something similar :)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 18, 2014 5:49 pm

thank you very much, for pointing this out! :D i will modify my scritp!
B
19
S
7
G
1
Posts: 222
Reputation: 2,551


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests