# I wanna make a DICE ROLL!!

Get help using Construct 2

### » Mon Mar 30, 2015 3:38 pm

How do i do a dice roll??
For example: i wanna dice to roll from 1-110

if it rolls 1-49 -Action 1 happens
If it rolls 50-99 -Action 2 happens
and if it rolls 100-110 -Action 3 happens!
B
10
S
1
Posts: 39
Reputation: 588

### » Mon Mar 30, 2015 3:52 pm

When you say "dice roll," I am guessing you mean you want the computer to choose a random value. Take a look in the manual at the random() system expression:
https://www.scirra.com/manual/126/system-expressions

Since random returns a float (or floating point number), the return will be a decimal. You will want to get the integer value from it.

Something like this would get what you want:
int(random(1,111))
*note: random returns the a number below the high value so to get 110, the high needs to be 111.
B
41
S
12
G
11
Posts: 331
Reputation: 7,767

### » Mon Mar 30, 2015 4:37 pm

To add to above. To get actions to happen when you do your dice role you will want to make a function.

When action calls for the dice to be thrown do function "dice roll"

Then in another event you will have On function "roll dice" set a var to int(random(1-111) then in sub events you will want the use the compare value event. in the first one you will want to compare var dice roll = range(1-49) then do action 1. the same for the other sub events but make sure they are on the same level as the first one

>Function
>>event
>>event
>>event

not
>Function
>>event
>>>event
B
7
S
3
Posts: 113
Reputation: 1,295

### » Mon Mar 30, 2015 5:04 pm

That helped a lot. Thank you !
B
10
S
1
Posts: 39
Reputation: 588

### » Mon Apr 13, 2015 4:05 pm

I'm a noob and I dont understand how do make a random dice roll still....Any more help would be appreciated
B
10
S
1
Posts: 39
Reputation: 588

### » Mon Apr 13, 2015 4:18 pm

If you could first explain what you expect with a dice roll, it might be easier to tell you how to do it..

The above comments explain how to get a random number.
Once you get the random number you can compare it and attach the actions you'd like to set.

What part are you having trouble with or was your initial question misunderstood?
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

### » Mon Apr 13, 2015 4:23 pm

My question was understood perfectly, but I have trouble executing it in construct.
I want every random 1-3 seconds that program throws a dice and a random number between 1-110.
and for numbers between :
1-49 executes animation 1
50-99 executes animation 2
100-110 animation 3
Step by step instructions would be great
B
10
S
1
Posts: 39
Reputation: 588

### » Mon Apr 13, 2015 4:32 pm

Should be something like this:

Create a global variable DiceRoll

triggered event (on sprite clicked?)
- system set variable DiceRoll = int(random(1,111))
- Function call "DiceAction" with parameter0 DiceRoll

on function "DiceAction"
- Function if parameter0 is < 50
> (add the action you'd like)
- Function if parameter0 > 49
- Function if parameter0 < 100
> (add the action you'd like)
- Function if parameter0 > 100
> (add the action you'd like)
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