[SOLVED] Make a more complex dice (random number generator)?

Get help using Construct 2

Post » Mon Aug 10, 2015 10:27 pm

@lukezero just a thought...
try to avoid "While" loops..... whenever you can..
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Mon Aug 10, 2015 11:29 pm

Perhaps he could use a function to avoid "While" loops?
Image Image
B
25
S
14
G
136
Posts: 875
Reputation: 71,003

Post » Tue Aug 11, 2015 12:31 am

"while" can be very useful to use. No reason to avoid it. You just need to make sure you're not causing an infinite loop by using it.

The method I proposed was to choose a random number and if it's either of the last two values it tries again. The only drawback is it could have the chance of looping a lot if one of the last values gets picked over and over again, but that is a slim chance in this case.

The method korbaach suggests is to have a list of all the numbers except the two last and choose one of them. Arrays could be used to do it or even text like the following.

number cur=0
number last1=0
number last2=0
text list=""

on click
--- set last2 to last1
--- set last1 to cur
--- set list to replace(replace("123456", str(last1), ""), str(last2), "")
--- set cur to int(mid(list,int(random(len(list))),1))
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Tue Aug 11, 2015 5:19 am

R0J0hound wrote:"while" can be very useful to use. No reason to avoid it.


@R0J0hound Of course, you're right,my fault...perhaps better advice was, be extremely careful when you use "While" loops :)
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Previous

Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, kellehk, TRMG and 28 guests