GefrManny 0 Posted February 22, 2007 Hey all. I've recently tried to come up with a more universal SQF script that checks if a player has a specified class and is therefor allowed (or not) to enter a vehicle. However either the parser has difficulties with blocks within blocks, or I messed up the syntax pretty good. Either way, I'm out of ideas. The whole script is called from the vehicle's getin-eventhandler, this addEventHandler ["getin", { _this exec "thescriptbelow.sqf" }]. Replacing exec with execVM only leads to error output supression, but that's about it :-/ The script: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment " ---- SETUP SECTION ---- make modifications here ---- "; comment "ALLOWED CLASSES"; comment "Which vehicle kind requires which class?"; comment "Values: [ vehicle class name, [ allowed unit class 1, allowed unit class 2, etc. ] ]"; comment "Check http://community.bistudio.com/wiki/ArmA:_CfgVehicles for class hierarchy!"; _allowed = ["StrykerBase", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"]]; _allowed = +["BRDM2", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"]]; _allowed = +["Tank", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"]]; _allowed = +["Air", ["SoldierWPilot", "SoldierGPilot", "SoldierEPilot"]]; comment "FREE POSITIONS"; comment "No class check for these positions (possible: driver, gunner or cargo):"; _free = ["cargo", "gunner"]; comment " ---- END OFSETUP SECTION ---- keep out unless you have a reason to meddle with it ---- "; _veh = _this select 0; _pos = _this select 1; _unit = _this select 2; _t_unit = typeOf _unit; _t_veh = typeOf _veh; hint format ["%1 is a %2 and gets in %3 position of %4", name _unit, _t_unit, _pos, _t_veh]; _do_eject = -1; if (!(_pos in _free)) then { for [{_vi = 0}, {((_vi < (count _allowed)) and (_do_eject == -1))}, {_vi = (_vi + 2)}] do { _veh_kind = _allowed select _vi; if (_veh isKindOf _veh_kind) then { hint format ["%1 is a kind of %2", typeOf _veh, _veh_kind]; _unit_kind = _allowed select (_vi + 1); _do_eject = 1; for [{_ui = 0}, {((_ui < (count _unit_kind)) and (_do_eject == 1))}, {_ui = (_ui + 1)}] do { _allowed = (_unit isKindOf (_unit_kind select _ui)); if (_allowed) then { _do_eject = 0; }; }; }; }; }; if (_do_eject == 1) then { _unit action ["EJECT", _veh]; }; Thanks in advance, Manny Share this post Link to post Share on other sites
charonos 0 Posted February 22, 2007 Well, that can take long to count the brackets. Quote[/b] ]Replacing exec with execVM only leads to error output supression You have to use execVM or spawn if you use that syntax. If i use notepad for writing the script (there is better editors ...) then i usually add bracket count comments until the code is fine: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (!(_pos in _free)) then { // 1 open for [{_vi = 0}, {((_vi < (count _allowed)) and (_do_eject == -1))}, {_vi = (_vi + 2)}] do { // 2 open _veh_kind = _allowed select _vi; if (_veh isKindOf _veh_kind) then { // 3 open hint format ["%1 is a kind of %2", typeOf _veh, _veh_kind]; _unit_kind = _allowed select (_vi + 1); _do_eject = 1; for [{_ui = 0}, {((_ui < (count _unit_kind)) and (_do_eject == 1))}, {_ui = (_ui + 1)}] do { // 4 open _allowed = !(_unit isKindOf (_unit_kind select _ui)); if (_allowed) then { _do_eject = 0; }; }; // 3 open }; // 2 open }; // 1 open }; // all closed So the number of brackets seems to be fine, the error must be somewhere else... What is the parser's error message exactly? EDIT: Try to leave the brackets in this expression: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> {_vi = (_vi + 2)} it should work just with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> {_vi = _vi + 2} Share this post Link to post Share on other sites
kronzky 5 Posted February 22, 2007 You need to get some sort of programmer's editor (I'm using UltraEdit, but there are lots others to choose from out there). That way the editor will show you exactly where the matching brackets are (no more counting them), and you can also use the code highlighting to find simple syntax errors (local vs. global variables, wrong commands, etc.). Here's how a few lines of code look like in UltraEdit: Share this post Link to post Share on other sites
GefrManny 0 Posted February 22, 2007 Interesting. Didn't know that SQF-files actually required execVM or spawn. Most of my (simple) scripts seemed to work with exec. execVM tells me no error, but doesn't really seem to work either (_do_eject always is -1 if I add hint format ["Eject: %1, _do_eject] after all the code). exec however leaves me with a simple '|#|};' Error missing { and nothing further being specified. Btw, I my editor features syntax highlighting, the { } count seems to be equal. Edit: Quote[/b] ]You need to get some sort of programmer's editor (I'm using UltraEdit, but there are lots others to choose from out there). Exactly that one. Share this post Link to post Share on other sites
GefrManny 0 Posted February 22, 2007 I've located the problem, the root of all evil lies herein: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_allowed = ["StrykerBase", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"]]; _allowed = +["BRDM2", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"]]; _allowed = +["Tank", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"]]; _allowed = +["Air", ["SoldierWPilot", "SoldierGPilot", "SoldierEPilot"]]; I accidently confused the unary +array operator as union, whereas it actually is just "copy that array". Hence my _allowed only contained the last entry. Should be working now with the following script: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment " ---- SETUP SECTION ---- make modifications here ---- "; comment "ALLOWED CLASSES"; comment "Which vehicle kind requires which class?"; comment "Values: [ vehicle class name, [ allowed unit class 1, allowed unit class 2, etc. ] ]"; comment "Check http://community.bistudio.com/wiki/ArmA:_CfgVehicles for class hierarchy!"; _allowed = [ "StrykerBase", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"], "BRDM2", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"], "Tank", ["SoldierECrew", "SoldierWCrew", "SoldierGCrew"], "Air", ["SoldierWPilot", "SoldierGPilot", "SoldierEPilot"] ]; comment "FREE POSITIONS"; comment "No class check for these positions (possible: driver, gunner or cargo):"; _free = ["cargo"]; comment " ---- END OFSETUP SECTION ---- keep out unless you have a reason to meddle with it ---- "; _veh = _this select 0; _pos = _this select 1; _unit = _this select 2; _t_unit = typeOf _unit; _t_veh = typeOf _veh; _entries = count _allowed; _do_eject = 0; if (!(_pos in _free)) then { for [{_vi = 0}, {((_vi < _entries) and (_do_eject == 0))}, {_vi = _vi + 2}] do { _veh_kind = _allowed select _vi; if (_veh isKindOf _veh_kind) then { _unit_kind = _allowed select (_vi + 1); _do_eject = 1; _unit_kinds = count _unit_kind; for [{_ui = 0}, {((_ui < _unit_kinds) and (_do_eject == 1))}, {_ui = _ui + 1}] do { _allowed = _unit isKindOf (_unit_kind select _ui); if (_allowed) then { _do_eject = 2; }; }; }; }; }; if (_do_eject == 1) then { _unit action ["EJECT", _veh]; }; Case solved, thanks to everyone. Sincerely, Manny Share this post Link to post Share on other sites