• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Conversion problem

Status
Not open for further replies.
Level 6
Joined
Jan 16, 2013
Messages
68
So, in my map I am mainly using chat commands.
Some of them require an integer to be typed in.
In the triggers the integers are being converted to strings so that I can use them as substrings.
The problem is that, if someone types in something that isn't an integer there the game instantly crashes on me which could be problematic in multiplayer.

So, how do I check if that substring can be converted or not before actually trying so that if it can't the program doesn't exit?
 
Last edited by a moderator:
Generally, checking if a string can be considered an integer is a two-step process:

(1) Try converting it to an integer. If it returns a number that is not 0, then it succeeded and you can use it. If it returned 0, then you must proceed to step 2.
(2) Loop through the characters and check if the characters are all 0 or a "." if you want to allow decimals. If they are something else, then it is not a number and you should ignore the command.

However, it shouldn't be causing a crash. You should post the trigger. Off the top of my head, I'm guessing you're using it as a player index. When passed an invalid player index, the game will instantly cause a crash (valid indexes are 1-16 in GUI, 0-15 in JASS). In your case, they may be passing something weird and it'll default to 0, which gets turned into Player(-1) in JASS, thus causing a crash. If you can, just ignore the commands that result in 0. If a "0" command is significant, then you'll have to do the check described in step (2) above.
 
Status
Not open for further replies.
Top