[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..
Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Mon Aug 10, 2015 11:29 pm

Perhaps he could use a function to avoid "While" loops?
Image Image
B
22
S
13
G
129
Posts: 869
Reputation: 67,316

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
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

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 :)
Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Previous

Return to How do I....?

Who is online

Users browsing this forum: Lancifer, MadSpy and 7 guests