Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Hi everyone, I have a type question, I'm pretty sure it's a silly one, but it has been half an hour, and I could not find anything that answer my question. (I'm french so my english is bad). 
What is the simplest way to convert a string into a number ?

a:"1"
                "1" typeof a                 "string" <- Okay a:"%i" format a                 "1" <- Why not a number ? a:a+0                 1 <- number
(+1)

When the distinction between a number and a string matters, the simplest way to convert the string into a number is with an arithmetic identity operation, like adding zero, as in your last example.

The format operator is for converting data into strings (or lists of strings); its counterpart for decomposing strings into other values is "parse":

 "%i" parse "123"
123
 "%i|%i|%i" parse "123|34|89"
(123,34,89)
(+1)

Thank you so much ! I was completely lost!