(solved)choose a frame between 2 different ranges

Get help using Construct 2

Post » Tue Apr 28, 2015 10:04 am


per @korbaach
solution is:

choose(int(random(0,20)),int(random(21,39)))


The original question was:

So I know how to ::
choose(0,1,2,3,4,5,6,7,8) to select a certain frame number
and I know how to
int(random(0,39)) to randomly select a whole number between 0 and 38.

but what if I wanted to
randomly select a frame number between 2 different ranges?
for example:
I have 40 frames, and I want to NOT select one of them;
for example frame 20

I could do
choose(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39)
but this seems pretty long and time consuming if I had multiple events doing the same thing with a different number, so I was hoping that there was a way to
do something like this:
choose(0thru19&21thru39)
int(random(0,19)&(21,39))
but these don't work.

Anyone know a solution?
is there one?

-
-
-

per @korbaach
solution is:

choose(int(random(0,19)),int(random(21,39)))
Last edited by producermark11 on Tue Apr 28, 2015 1:10 pm, edited 3 times in total.
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Tue Apr 28, 2015 11:08 am

try...

choose(int(random(19)),int(random(21,39)))
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Tue Apr 28, 2015 11:12 am

I think this might be some work-around in general idea:

[pseudo code]
randomNumber1 = random(1..19)
randomNumber2 = random(21..39)
pickNumber = random(1,2)

if pickNumber == 1
return randomNumber1
else return randomNumber2

---- or a bit prettier way ----
pickRange = random(1,2)
if pickRange == 1
return random(1..19)
else return random(21..39)
ImageImage
B
27
S
16
G
68
Posts: 946
Reputation: 38,601

Post » Tue Apr 28, 2015 11:34 am

@korbaach
Thanks for the answer.
correct me if I am wrong but I think you meant
choose(int(random(0,19)),int(random(21,39)))

:-)

:mrgreen: sweet :!:

just so people visiting this topic don't get confused :oops:
Last edited by producermark11 on Tue Apr 28, 2015 11:37 am, edited 1 time in total.
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Tue Apr 28, 2015 11:36 am

@BackendFreak
thanks for answering
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Tue Apr 28, 2015 11:51 am

oh,
Just a quick reminder to those looking at this forum post ( cause I actually forgot after I tried to test the code)....
Per the manual:
Random(N) - Returns a random number between 0 and N, not including N
so in the above example,
to exclude frame 20
the code would actually need to be
choose(int(random(0,20)),int(random(21,39)))
B
35
S
10
G
4
Posts: 250
Reputation: 7,908


Return to How do I....?

Who is online

Users browsing this forum: Ryan Kocourek and 2 guests