Randon Function

Get help using Construct 2

Post » Fri Nov 25, 2011 12:41 am

Guys,

I have a doubt... Id like to make my random interval between 1 and 7, and where I find the function syntax in C2 about it ?

The commom is random(x), in some examples...

Thx for any help
"keep calm we have giant robots!"
B
21
S
5
G
5
Posts: 94
Reputation: 3,405

Post » Fri Nov 25, 2011 12:52 am

Hi amarcelo,

Yes it is Random(7) or you could do Random(1,7)
also when you are typing in the function "Random(" the function syntax will show up for you.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Mon Nov 28, 2011 1:34 pm

Thx again !!!!

"keep calm we have giant robots!"
B
21
S
5
G
5
Posts: 94
Reputation: 3,405

Post » Mon Nov 28, 2011 1:44 pm

I'm working on this. I only wanted whole numbers, so I used int(random(7)). Trying to figure out how to create a random calculation symbol appear now though :( random(*,/,-,+) doesn't seem to work.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Mon Nov 28, 2011 2:49 pm

@AnD4D - try splitting a comma-separated string with a random index, like this:

tokenat("+,-,*,/", int(random(4)), ",")
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Mon Nov 28, 2011 6:50 pm

I can't seem to crack it! http://dl.dropbox.com/u/50465867/TextAdventure.capx

I tried to use the code using the variable in an array, but it didn't work unless I used a global variable. I have the program set to have the "sum" text display the maths symbol. Am I going about this the completely wrong way?
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Mon Nov 28, 2011 8:02 pm

your sum variable should be a text not a number
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Nov 28, 2011 8:22 pm

That's got it working... but now I just need to figure out how to work the expression. I have Var1&gsum&Var2... so that var1 and 2 are altered by whatever gsum is. Doesn't seem to like that, so I tried commas, which causes an error, and finally the + symbol, which works but gives the wrong results.

Any ideas?
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Mon Nov 28, 2011 8:32 pm

Succeeded using 4 events. Sure there's a way to do it using just one.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Tue Nov 29, 2011 9:44 am

You probabaly will have to separate calculation from character display.

For instance
[code]local variable operation
on whatever you want to do -> set operation to random(4)
---- operation = 0 -> do an addition
---- operation = 1 -> do a substraction
---- operation = 2 -> do a multiply
---- operation = 3 -> do a divide
---- always -> set text to tokenat("+,-,*,/",operation,",")[/code]

There's really no way around that. 'cause you can't do something like
eval(n1&"*"&n2) to create and evaluate an operation from a string in c2
Yann2011-11-29 09:46:09
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Next

Return to How do I....?

Who is online

Users browsing this forum: randomly and 17 guests