Exception handling: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(completed)
Line 1: Line 1:
[[Category:Armed Assault:Scripting]]
[[Category:Armed Assault: Scripting]]


In Armed Assault is implemented system of [[Armde Assault:Scripting commands|scripting commands]] which allows your scripts react to lots of kinds of exceptions.
In Armed Assault is implemented system of [[Armde Assault:Scripting commands|scripting commands]] which allows your scripts react to lots of kinds of exceptions.
Standard construction is:
Standard construction is:


try {
try {
    //block, that can throw exception
    //block, that can throw exception
    if (_name == "") then {
    if (_name == "") then {
        throw "invalid _name"
        throw "invalid _name"
    } else {
    } else {
        TitleText ["And the name is:", "PLAIN DOWN"]
        TitleText [format["Good morning, Captain %1.", _name], "PLAIN DOWN"]
        ~1
        ~1
        TitleText [_name, "PLAIN DOWN"]
        TitleText [_name, "PLAIN DOWN"]
}  
}<br>
catch {
    //block, that processes an exception
    if (_exception == "no name") then {
        echo "Name wasn't entred"
        TitleText ["And the name isn't", "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"]
    }
}


{{AnswerMe}}
{{AnswerMe}}
Probably is possible this too:
Probably is this possible too:


try {
{{Box File|.../fireBomb.sqs|<pre>
    TitleText ["Sgt. Detritus: He have luck, but next time I'll kill him!", "PLAIN DOWN"]
_car = _this select 0
    [jeepOne] exec "killDriver.sqs"
if (_car emptyPositions "driver") || _car emptyPositions "gunner" || _car emptyPositions "commander" ) then {
}
    throw "vehicle empty"
} else {
    if (3 < random 10) then {
        throw "bomb failed"
    } else {
        _car setDammage 1
        if (alive Guba) then {
            throw "bastard still alive"
        }
    }
}     
</pre>}}


catch {
try {
    if (_exception == "car empty") then {
    TitleText ["Sgt. Detritus: I get bomb to his car ;-)", "PLAIN DOWN"]
        TitleText ["Sgt. Detritus: He have luck, but next time I'll kill him!", "PLAIN DOWN"]
    [jeepOne] exec "fireBomb.sqs"
    } else {
}<br>
        TitleText ["Sgt. Detritus: Some strange error appears...", "PLAIN DOWN"]
catch {
}
    if (_exception == "vehicle empty") then {
        TitleText ["Sgt. Detritus: He have luck, but next time I'll kill him!", "PLAIN DOWN"]
    } else {
        TitleText [format["Sgt. Detritus: Some strange error appears... %1... hmm... another time I'll get him!", _exception], "PLAIN DOWN"]
}

Revision as of 18:26, 22 July 2006


In Armed Assault is implemented system of scripting commands which 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 [format["Good morning, Captain %1.", _name], "PLAIN DOWN"]
        ~1
        TitleText [_name, "PLAIN DOWN"]
}
catch { //block, that processes an exception if (_exception == "no name") then { echo "Name wasn't entred" TitleText ["And the name isn't", "PLAIN DOWN"] } }


Template:AnswerMe Probably is this possible too:

Template:Box File

try {
    TitleText ["Sgt. Detritus: I get bomb to his car ;-)", "PLAIN DOWN"]
    [jeepOne] exec "fireBomb.sqs"
}
catch { if (_exception == "vehicle empty") then { TitleText ["Sgt. Detritus: He have luck, but next time I'll kill him!", "PLAIN DOWN"] } else { TitleText [format["Sgt. Detritus: Some strange error appears... %1... hmm... another time I'll get him!", _exception], "PLAIN DOWN"] }