Exception handling

From Bohemia Interactive Community
Revision as of 16:41, 22 July 2006 by Djura (talk | contribs) (I'll write next part later...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


In Armed Assault is implemented system of scripting commands witch allows your scripts react to lots of kinds of exceptions. Standard construction is:

try {

   //block, that can throw exception
   if (_name == "") then {
       throw "invalid _name"
   } else {
       TitleText ["And the name is:", "PLAIN DOWN"]
       ~1
       TitleText [_name, "PLAIN DOWN"]

}

catch {

   //block, that processes an exception
   if (_exception == "invalid _name") then {
       echo "Wrong name detected"
       TitleText ["And the name isn't", "PLAIN DOWN"]
   }

}

Template:AnswerMe Probably is possible this too:

try {

   TitleText ["Sgt. Detritus: He have luck, but next time I'll kill him!", "PLAIN DOWN"]
   [jeepOne] exec "killDriver.sqs"

}

catch {

   if (_exception == "car empty") then {
       TitleText ["Sgt. Detritus: He have luck, but next time I'll kill him!", "PLAIN DOWN"]
   } else {
       TitleText ["Sgt. Detritus: Some strange error appears...", "PLAIN DOWN"]

}