Author Topic: Is input number?  (Read 546 times)

0 Members and 1 Guest are viewing this topic.

Offline ShadowDancer

  • Major(1)
  • Posts: 22
Is input number?
« on: March 25, 2010, 06:03:30 pm »
How to check if user input is number? Example i want to call skill by id. If i use StrToInt and user write '/cast asd' couple times server will crash. How to avoid it?
Sorry, I'm not native English speaker...

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Is input number?
« Reply #1 on: March 25, 2010, 08:43:12 pm »
Code: [Select]
try
// stuff with StrtoInt
// ...
except
// it is not an int, so do other stuff
end;

StrtoInt will throw an exception if it's input can not be turned into an int. In case you don't know what an exception is: uhm.. well.... if something throws an exception, it kind of like skips code until it finds itself in a 'try catch' statement (usually called 'try catch' since the keyword to catch an exception is usually 'catch', not 'except' like in pascal) and gos into the stuff after the except. If you already knew what an exception was, then ignore that. :P
There are a few functions that can help you do exception stuff urself, ask if u want em, im lazy right now kuz not even sure if u wanted any of that info ^^

Offline ShadowDancer

  • Major(1)
  • Posts: 22
Re: Is input number?
« Reply #2 on: March 26, 2010, 11:00:17 am »
Thanks, solved. Didn't know, that is exception system in soldat :)
Sorry, I'm not native English speaker...