# Randon Function

0 favourites
• 10 posts
• Guys,

I have a doubt... I�d 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

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

• Thx again !!!!

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

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

tokenat("+,-,*,/", int(random(4)), ",")

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

• your sum variable should be a text not a number

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

• Succeeded using 4 events. Sure there's a way to do it using just one.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• You probabaly will have to separate calculation from character display.

For instance

``````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,",")``````

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