global variable value isn't pulling the corresponding image

Just started using Construct 2? Post your questions here

Post » Tue Mar 01, 2016 8:33 pm

Hello! I'm having a problem with my game, I was trying to do something like a switch structure so that when a global variable takes a specific value, a certain image becomes visible, like this

Image

but when executing I sometimes see the right image according to the global value popping up and sometimes I don't. Does anybody has an idea what could be going on?
B
3
Posts: 3
Reputation: 181

Post » Tue Mar 01, 2016 10:36 pm

floor(random(1,4)) = choose(1,2,3)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Thu Mar 03, 2016 12:25 am

ramones wrote:floor(random(1,4)) = choose(1,2,3)



Thank you for the reply Ramones! It didn't work but I'm gonna give it a try with https://www.scirra.com/forum/plugin-switchcase_t64458
B
3
Posts: 3
Reputation: 181

Post » Thu Mar 03, 2016 9:33 pm

I was too tired to type a proper reply :) What I meant was that floor(random(1,4)) will only give you 1, 2, or 3 so the gblVarOpcFracc = 4 condition will never be true. Another possible issue is that you are setting the timescale to 0 and then using wait 0.5 seconds. That wait will never happen when the timescale is 0.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Thu Mar 03, 2016 9:42 pm

Sorry that I hijack this topic, but when I read the reply a question came to my mind: Does Random always return an integer? If yes, what if I need a decimal?
B
5
Posts: 15
Reputation: 255

Post » Thu Mar 03, 2016 9:45 pm

@Kincaid No random() doesn't return an integer - you use floor() to round it to an integer.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Thu Mar 03, 2016 11:06 pm

Ah, I see. There is ceil, floor and round. And how do you round to, let's say, 2 decimal places?
B
5
Posts: 15
Reputation: 255

Post » Sat Mar 05, 2016 11:31 pm

Multiply by 100, round it, decide by 100 :-)
B
12
S
2
G
1
Posts: 42
Reputation: 879

Post » Sun Mar 06, 2016 12:23 am

Allright, thanks. Sorry again for hijacking this thread. Back to topic now. :)
B
5
Posts: 15
Reputation: 255


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests