Can I always rely on ToInt() to work like this?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Can I always rely on ToInt() to work like this?

Post by Matt »

I want to take a string that looks like this:

aaa123bbb456

and retrieve the number that comes right after "aaa", wherever "aaa" is and however long the number might be (123456, 12, etc.).


Can I rely on ToInt() (i.e., ToInt(10)) to always parse
"bbb" as 0
"bbb4" as 0
"123b" as 123
"123bbb456" as 123
etc.

so that I can just ToInt() whatever is to the right of "aaa" without checking where the consecutive numerals end?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Can I always rely on ToInt() to work like this?

Post by Graf Zahl »

Most of the time, yes, but beware of a few special cases:

0x???? gets interpreted as hex number.
124e45 may get converted to a float first. It shouldn't when using toInt, but I'd be careful with that.
Post Reply

Return to “Scripting”