Notifications
Clear all

[Closed] How to convert string to integer?

How to convert string to integer?
because this maxscript listener it shows “[10,10,0]” but I would like [10,10,0]

5 Replies

Do you mean, you want to access an object like a box or sth else and furthermore transform it, for example?

Yes, I would like convert from string to point3 for create box.

If you simply had a integer as a string such as “6”. Then you could say:

Var1 = “6” as integer.

In your example you hav ea Point3 Value, which unfortunately I dont think is quite so simple. I may well not be suggesting the best way, but you could filter the string out to separate out the x,y,z values and then convert each to an integer and combine them back into a point3 value.

For example a function that would make this conversion would be :



--Function to Convert a string of type "[a,b,c]" to a true point3 value, where a,b,c are integers
fn StringtoPoint3Converter PointString = 
(
Elements = filterstring PointString "[,]"
XElement = Elements[1] as integer
YElement = Elements[2] as integer
ZElement = Elements[3] as integer

NewPoint3 =  [XElement ,YElement ,ZElement ]

)--End of StringtoPoint3Converter 


--We can use this in the following way
ExStringPoint = "[12,10,9]"
NicePoint3Value = StringtoPoint3Converter ExStringPoint


I have ot really hada time to check this properly… but hopefully it will help a bit. Fire anymore question our way

Good luck,

rich

in the case of a point3, an easier way would be:

myVar = execute "[10,10,10]"

nice One Gravey

I have no idea why I do it, but I always look for a really cunning convoluted solution! It would appear that in this case it particularly lacks the elegance of your approach!

lol

rich