how to convert string to int ?

Monkey Forums/Monkey Programming/how to convert string to int ?

Lugato(Posted 2011) [#1]
hi to all ..

I'm reading a text file that stored configurations parameters and need convert some values to int .. I don't see anything in documentation about that, can anyone help me ?

thanks


therevills(Posted 2011) [#2]
You need to cast it to an Int:


Local str:String = "1"
Print str
Local x:Int = Int(str.Trim())
Print x




Lugato(Posted 2011) [#3]
Thanks therevills ;)

The build are ok now.. but when I'll execute the application in Mac the window close..

I need attribute some values to a variable that is a array, because i'm triyng to make a tilemap, I tried:

Local map:= [New Int[15],New Int[15]]

store in a text file this structure:
1|2|2|2|22|22|22|22|22|22|22|22|22|22
1|2|2|2|22|22|22|22|22|22|22|22|22|22
..
1|2|2|2|22|22|22|22|22|22|22|22|22|22

and make this to read and attibute the values to the array:

mapFile = LoadString( "gameMap-01.map" )

Local maxColuns = 0
Local maxLines = 0
For Local line$=Eachin mapFile.Split( "~n" )
For Local iten$=Eachin line.Split( "|" )
maxColuns = maxColuns + 1
map[maxLines][maxColuns]=Int(iten.Trim())
Next
maxLines = maxLines + 1
Next


Do you have any idea that are causing the error

thanks


therevills(Posted 2011) [#4]
I havent run your code, but lookin at your LoadString you are trying to load a .map file and Monkey will only load .txt, .xml and .json:



Monkey will only load files that end with the following file extensions: .txt, .xml, .json.



Also are you running in debug mode to try to find the error?


Lugato(Posted 2011) [#5]
two things:
1- I created a debug using DrawText and the program can read the values stored in the file.

2- How can I enable the debug mode ??


therevills(Posted 2011) [#6]
Hmmm everytime I tried to open a text file with an extension other than .txt it never reads the values in.

If you are using Monk, click Program > Build Options > Debug Build


Lugato(Posted 2011) [#7]
I have checked the "Debug Build" in menu, but the buttons to Debug don't are enabled :(

I'm using a Mac and Building to GLFW ...


Lugato(Posted 2011) [#8]
Very strange I tried to put a fix number in attribution line:

before: map[maxLines][maxColuns]=Int(iten.Trim())

after: map[maxLines][maxColuns]=10

the same error occur .. :(

maybe the error are in the array ... very strange :(


therevills(Posted 2011) [#9]
I used a tilemap for my quick platform game and posted the source code here:

http://www.monkeycoder.co.nz/Community/posts.php?topic=449

Hope it helps.