[SOLVED]Trying to write the right expresion

For questions about using Classic.

Post » Wed Jul 06, 2011 1:02 pm

I have a tiled BG. But i want the texture to be randomly loaded on the start of layout.
i puropusly named the tiledBG pngs 1.png, 2.png, 3.png... so i can use "Random(#)" expresion on them instead of using variable switches.
The problem is i cant write a working expresion for this.

i tried
AppPath & Random(10)"png"
but this doent work.

AppPath & Random(10)&"png"
AppPath & "Random(10)png"
returned negative too.

Anybody have idea how to write this correctly?The_Funny_Guy2011-07-06 13:39:40
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Wed Jul 06, 2011 1:06 pm

The second one is corrent, but you forgot the '.' in ".png"
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Wed Jul 06, 2011 1:07 pm

AppPath & random(10) & ".png" or
AppPath & "" & random(10) & ".png" - sometimes i have to add empty "" for that to work and sometimes works without it :/

if your files start at 1.png add random(10)+1

ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Wed Jul 06, 2011 1:39 pm

ahh thank you guys. i am a clumsy GameDev ^^ i always lost this small little things that makes the whole structure calapse
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Wed Jul 06, 2011 2:20 pm

Random(10) +1 unless you have a 0.png
Like shinkan saidnewt2011-07-06 14:22:31
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Wed Jul 06, 2011 3:59 pm

[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.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Jul 06, 2011 4:00 pm

oww that's a great tip, thanks tulamide!
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Wed Jul 06, 2011 10:23 pm

[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.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Thu Jul 07, 2011 6:19 am

okey. so to not make another thread:
do you know if theres a way to write an expresion so the value would be picked randomly but from a pattern?
example.
i want the angle of sprite X, to be randomly set from 0, 90, 180 or 270.
Is there a way to do this without the use of switches?
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

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

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests