# (solved)choose a frame between 2 different ranges

From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
• 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?

-

-

-

solution is:

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

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• try...

choose(int(random(19)),int(random(21,39)))

• 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)

correct me if I am wrong but I think you meant

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

just so people visiting this topic don't get confused

• 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)))

• 6 posts