String to Value

For questions about using Classic.

Post » Tue Dec 30, 2008 2:47 pm

hi,
i'm loading a csv-file of xy-coordinates into a ListBox object to use a 'For each line' loop to spawn sprites at the specified positions. but ListBox.LineData() appears to return strings - or i suspect it to, because the results are always interpreted as 0 (zero) in the coordinate fields of the 'Create' action.

is there a counterpart to str(value) that can turn strings into values?

thanks for your time!
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Tue Dec 30, 2008 3:01 pm

Use 'int()'.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Tue Dec 30, 2008 3:13 pm

thanks!

two things:
[list:2ydtm257]
[*:2ydtm257]when using ListBox.LineText() instead of ~.LineData(), it works even without enclosing int()[/*:m:2ydtm257]
[*:2ydtm257]when using ~.LineData(), it does not work in any case[/*:m:2ydtm257][/list:u:2ydtm257]

off topic, but what is LineData supposed to return?
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Tue Dec 30, 2008 3:15 pm

LineData only returns something if you set data for the line (using the Set Line Data action); this is useful for storing extra data on lines other than text. In this case you'll want to use LineText, which is automatically converted to an integer by the parser.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Tue Dec 30, 2008 3:27 pm

In all of Construct, passing a string to a number parameter automatically converts it, so you can pass either "500" or 500, it doesn't matter. As Rich pointed out, LineData does not give the text, LineText does :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Jan 04, 2009 8:48 am

Nice and Nice!
I was actually adding a private variable to my text boxes to store additional information. I guess I didn't have to.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests