Changing a string to a integer

For questions about using Classic.

Post » Sun Nov 07, 2010 10:34 pm

I have a text box that asks the user for a number, then I have a line of text that changes and adds 10 to that number, but I can't add 10 to a string. Is there a way of asking for only an integer?
B
1
G
2
Posts: 4
Reputation: 633

Post » Sun Nov 07, 2010 10:39 pm

int(string)

That's string to integer.

While str(value) is integer/float to string.

Check the wiki FAQ [url:17ziwpip]http://sourceforge.net/apps/mediawiki/construct/index.php?title=FAQ[/url:17ziwpip]
where it says "How do I convert between text and numbers?" as well as this: [url:17ziwpip]http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions[/url:17ziwpip].
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Sun Nov 07, 2010 10:45 pm

[quote="level_up":2qw76nzz]I have a text box that asks the user for a number, then I have a line of text that changes and adds 10 to that number, but I can't add 10 to a string. Is there a way of asking for only an integer?[/quote:2qw76nzz]
You just need to convert the text to an int or float.

Example:
A textbox with the text "11"
->Text: Set text to int(Text.Text) + 10
will set the textbox to the text "21"
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Nov 07, 2010 10:46 pm

Thanks guys, I flicked through the FAQ...must have missed it :roll:
*face palm*
B
1
G
2
Posts: 4
Reputation: 633


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests