Convert string to value?

For questions about using Classic.

Post » Sat Apr 04, 2009 7:37 pm

I have a resolution selector combobox. It has "640 x 480" etc. I use the text manipulator to seperate these numbers to change the resolution value, like so:

[code:dkp3q52y]
Set "reswidth" to:
TextManipulator.GetSubstring(" x ", 0)[/code:dkp3q52y]

It works, and the global variable is set to the correct number. But, even though it's set as a number variable, that number is actually a string. As such, none of my calculations using it work anymore.

In MMF you could change strings of numbers to numbers with "Val()" but I can't seem to find the equivalent here.
B
4
G
6
Posts: 32
Reputation: 1,514

Post » Sat Apr 04, 2009 7:42 pm

int() casts the value to an int.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sat Apr 04, 2009 9:53 pm

Strings are also converted to values where necessary. For example, you can set an object's X co-ordinate to "500", and it works the same as passing the number 500.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Sat Apr 04, 2009 11:15 pm

hmm...typecasting,may I know what other variable type Construct supports?
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Fri Apr 17, 2009 4:23 am

I'm having the same problem, I'm retrieving a value from a string however it doesn't recognize it as a value in the private variable. :?


edit: Yeah that int(string) seemed to make it work. :D
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Fri Apr 17, 2009 4:27 am

Float(value) casts to float
int(value) casts to int
str(value) casts to string
B
5
S
2
G
4
Posts: 632
Reputation: 2,829


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests