[SOLVED]Trying to write the right expresion

For questions about using Classic.

Post » Thu Jul 07, 2011 7:21 am

Do it with math:

random(3)* 90

Where is the problem? Don't think too complicated...GameForger2011-07-07 07:23:33
B
4
S
1
G
1
Posts: 49
Reputation: 997

Post » Thu Jul 07, 2011 7:43 am

this is one of those moments i want to smack myself in the face.
Ahhh... why i am always blind for the obvious solutions?
Thank you GF.

another thing. this:
AppPath & "" & random(10)+1 & ".png"

gives me error saying:
'+' does not work on 'integer' and 'string'

the heck?
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Thu Jul 07, 2011 10:45 am

Try AppPath & "" & str(random(10) + 1) & ".png"

Although, I don't understand why you have the "" in there, as that doesn't add anything to the string. Jayjay2011-07-07 10:45:54
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Jul 07, 2011 4:42 pm

[QUOTE=newt] [QUOTE=tulamide] [QUOTE=shinkan]...
sometimes i have to add empty "" for that to work and sometimes works without it :/
...[/QUOTE]

Although Construct tries its best to convert between numbers and text, you are free to explicitly convert to text with the expression 'str':

AppPath & str(random(10) + 1) & ".png"

This should work without exception.[/QUOTE]

Ampersand concatenates to string, so it should automatically be converted.
I've seen others use the plus sign, and it worked, but I can't think of a situation where that method would be better. [/QUOTE]

- That's what I said, Construct tries its best to convert.
- Never use the plus sign, the only sign you can rely on is ampersand.
- there are situations where Construct will be confused with the information given. Just create a text box and do:


      + System: Start of layout
      -> Text: Set text to AppPath & random(10) + 1 & ".png"

Do you now see, where that str method would be better?

EDIT: Sorry, after posting I realized that Jayjay already gave that example.tulamide2011-07-07 16:45:14
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests