ZNorQ 0 Posted September 13, 2007 I'm trying to create a script that enables a specific player become a mechanic. He/she shall have the possibility to repair any vehicle (air, sea, land) that has a damage between 10% and 59%, with the max repair capasity of 60%.. My script - which determines if the player (well, hopefully anyway) is near any vehicle that has a damage range between 10-59%, speed of zero and no people inside - will get a "repair vehicle" action added.. Unfortunatly I get an error message saying something like this; Quote[/b] ]while {true} |#|{Error do: Type string, expected code I've tried all I can to find the error, and I just can't find it... Here is the EXACT code which is run by ArmA; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (bRoleMechanicRunning) exitWith {false}; bRoleMechanicRunning = true; _plyr = _this select 0; // ADD ACTIONS TO RELEVANT PLAYERS while {true} do { _NearestVehicle = nearestObjects [_plyr, ["landvehicle", "Air", "Ship"], 10000] select 0; _NVSpeed = speed _NearestVehicle; _NVCrew = count crew _NearestVehicle; _NVDamage = damage _NearestVehicle; hint format["Vehicle: %1\nSpeed: %2\nCrew: %3\nDamage: %4\nAction: %5", _NearestVehicle, _NVSpeed, _NVCrew, _NVDamage, _NVAction]; if (_NVSpeed == 0) and (_NVCrew == 0) and (_NVDamage >= 10) and (_NVDamage <= 59) and (_aaMechanic = 0) then {_NVAction = true} else {_NVAction = false}; if (_NVAction) and (!_aaMechanic) then {_aaMechanic = _plyr addAction ["Repair Vehicle", "res\bat\cli\plr\actions\mechanic.sqf", "", -999, false, true, "teamSwitch"]}; if (!_NVAction) and (_aaMechanic) then {removeAction _aaMechanic; _aaMechanic = 0}; sleep 0.01; }; Can anyone please explain why this happens? ZNorQ Share this post Link to post Share on other sites
hoz 0 Posted September 13, 2007 try while {bRoleMechanicRunning==true} do { //good stuff here... }; I think that might work trying to find a while statement in one of my missions... Share this post Link to post Share on other sites
ZNorQ 0 Posted September 13, 2007 That's a negative - didn't work... I just don't get it... I'm pretty sure I've used while {true} do {}; before... ZNorQ Share this post Link to post Share on other sites
UNN 0 Posted September 13, 2007 Try it with just: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">While {True} Do     {     Sleep 0.1;     }; If thats ok, add the rest of the code a bit at a time. Share this post Link to post Share on other sites
squeeze 22 Posted September 13, 2007 and (_aaMechanic = 0)......_aaMechanic isn't init before the IF Share this post Link to post Share on other sites
ColonelSandersLite 0 Posted September 13, 2007 Arma likes to error on the top level of the command, instead of the erroneous command itself. There's probably nothing wrong with the while command there, but something wrong with one of the inner commands. Try commenting out the while and matching brace, like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if (bRoleMechanicRunning) exitWith {false}; bRoleMechanicRunning = true; _plyr = _this select 0; // ADD ACTIONS TO RELEVANT PLAYERS //while {true} do { _NearestVehicle = nearestObjects [_plyr, ["landvehicle", "Air", "Ship"], 10000] select 0; _NVSpeed = speed _NearestVehicle; _NVCrew = count crew _NearestVehicle; _NVDamage = damage _NearestVehicle; hint format["Vehicle: %1\nSpeed: %2\nCrew: %3\nDamage: %4\nAction: %5", _NearestVehicle, _NVSpeed, _NVCrew, _NVDamage, _NVAction]; if (_NVSpeed == 0) and (_NVCrew == 0) and (_NVDamage >= 10) and (_NVDamage <= 59) and (_aaMechanic = 0) then {_NVAction = true} else {_NVAction = false}; if (_NVAction) and (!_aaMechanic) then {_aaMechanic = _plyr addAction ["Repair Vehicle", "res\bat\cli\plr\actions\mechanic.sqf", "", -999, false, true, "teamSwitch"]}; if (!_NVAction) and (_aaMechanic) then {removeAction _aaMechanic; _aaMechanic = 0}; sleep 0.01; //}; Oh, and btw, your long if command is wrong. It should be: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> if ( (_NVSpeed == 0) and (_NVCrew == 0) and (_NVDamage >= 10) and (_NVDamage <= 59) and (_aaMechanic = 0) ) then { _NVAction = true; } else { _NVAction = false; }; And just to make sure you know this, although I'm sure you do: Multiline commands are only supported in sqf format. Sqf format is not handled by exec, but execVM instead. That comment is not meant to be patronising, but I have seen confusion over it before. Share this post Link to post Share on other sites
ZNorQ 0 Posted September 13, 2007 and (_aaMechanic = 0)......_aaMechanic isn't init before the IF Haven't had problems with that before, infact I'm using such programming in this exact mission and that works... Oh, and btw, your long if command is wrong. It should be:.. Yeah, I just figured that out, but still I get a damn error (pardon my french).. This is my altered code; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (bRoleMechanicRunning) exitWith {false}; bRoleMechanicRunning = true; _plyr = _this select 0; _whilerunning = true; // DETECT VEHICLES AROUND MECHANIC //while {true} do { _NearestVehicle = nearestObjects [_plyr, ["landvehicle", "Air", "Ship"], 10000]; _NearestVehicle = _NearestVehicle select 0; _NVSpeed = speed _NearestVehicle; _NVCrew = count crew _NearestVehicle; _NVDamage = damage _NearestVehicle; hint format["Vehicle: %1\nSpeed: %2\nCrew: %3\nDamage: %4\nAction: %5", _NearestVehicle, _NVSpeed, _NVCrew, _NVDamage, _NVAction]; // FOUND A VEHICLE? if ((_NVSpeed == 0) and (_NVCrew == 0) and (_NVDamage >= 10) and (_NVDamage <= 59) and (_aaMechanic == 0)) then {_NVAction = true} else {_NVAction = false}; // IF VEHICLE FOUND AND ACTION ISN'T ALREADY ADDED... if ((_NVAction) and (!_aaMechanic)) then {_aaMechanic = _plyr addAction ["Repair Vehicle", "res\bat\cli\plr\actions\mechanic.sqf", "", -999, false, true, "teamSwitch"]}; // IF VEHICLE NO LONGER FOUND BUT ACTION IS ADDED... if ((!_NVAction) and (_aaMechanic)) then {removeAction _aaMechanic; _aaMechanic = 0}; sleep 0.01; //}; As you can see, I've commented out the while-do statement (and it's ending };), and I get this error now; Quote[/b] ]if ((!_NVAction)and (_aaMechanic)) |#|then {remove... And just to make sure you know this, although I'm sure you do:Multiline commands are only supported in sqf format. Sqf format is not handled by exec, but execVM instead. That comment is not meant to be patronising, but I have seen confusion over it before. Hehe, I'm not insulted, I'm happy you are trying to cover all aspects - so thanks. (Oh, and yes, I do know about exec/sqs vs. execVM/sqf issue... I'm only using sqf files now, unless it's necessary to use sqs, as in onFlare.sqs, etc.) Share this post Link to post Share on other sites
squeeze 22 Posted September 14, 2007 _aaMechanic.....i see you put the extra = in but first you see if its == 0, than later you check if its true or false. Share this post Link to post Share on other sites
VictorFarbau 0 Posted September 14, 2007 Well, I bet ya the error is in the first consecutive statement right after "While {TRUE}". So this would be <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_NearestVehicle = Â nearestObjects [_plyr, ["landvehicle", "Air", "Ship"], 10000] select 0; Are you sure you can query for these class names? I don't know and can't check right now, but I only used classes like "Car","Tank", "Man" or "Motorcycle" so far which are sub-classes to the ones you query. VictorFarbau Share this post Link to post Share on other sites
moricky 211 Posted September 14, 2007 Try this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// IF VEHICLE FOUND AND ACTION ISN'T ALREADY ADDED... if ((_NVAction) and (isnil "_aaMechanic")) then {_aaMechanic = _plyr addAction ["Repair Vehicle", "res\bat\cli\plr\actions\mechanic.sqf", "", -999, false, true, "teamSwitch"]}; // IF VEHICLE NO LONGER FOUND BUT ACTION IS ADDED... if ((!_NVAction) and !(isnil "_aaMechanic")) then {removeAction _aaMechanic; _aaMechanic = 0}; What exactly is variable _NVAction? It have to be true or false, otherwise you should use isnil on it too. @VictorFarbau: Every config class defined under CfgVehicles can be checked in this command. Share this post Link to post Share on other sites
ZNorQ 0 Posted September 14, 2007 _aaMechanic.....i see you put the extra = in butfirst you see if its == 0, than later you check if its true or false. I'm not quite sure what you mean, but I was thinking that ArmA might not handle numbers properly as a booleans, so I did change the code to instead of testing it as true (anything than zero) or false (zero), it would test for a number greater than zero or zero... And it is now set to zero before the loop starts.. (See my new code in one of my answers below.. If you can't find it, I'm not finished writing the feedback yet.. ) Share this post Link to post Share on other sites
ZNorQ 0 Posted September 14, 2007 Well, I bet ya the error is in the first consecutive statement right after "While {TRUE}".So this would be <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_NearestVehicle = nearestObjects [_plyr, ["landvehicle", "Air", "Ship"], 10000] select 0; Are you sure you can query for these class names? I don't know and can't check right now, but I only used classes like "Car","Tank", "Man" or "Motorcycle" so far which are sub-classes to the ones you query. VictorFarbau All the class names I've is listed as valid in the kibi. I did a short test where it outputs the content of the result, and everything seems fine.. Share this post Link to post Share on other sites
ZNorQ 0 Posted September 14, 2007 Try this: if ((_NVAction) and (isnil "_aaMechanic")) It wouldn't work, because I've changed the code so that it sets this variable to zero (0) before the loop starts. (I'm interpeting isnil as a function to test if a variable haven't been declared..?) The variable is supposed to be the addAction ID.. What exactly is variable _NVAction? I'll try to write a description of the whole code, but I'll do that on my revised one.. (I'm working on it, so please bare with me on this..) Share this post Link to post Share on other sites
ZNorQ 0 Posted September 14, 2007 I'll try my best to explain my code, and I'll do that block by block.. But first I thought I'd explain what my intentions was in the first place; I'm creating co-op missions that consists of 27 players, some of whom got special functions like hacking, radio, a game master control screen, field mechanics, etc. There will be 3 field mechanics that can repair any vehicle that are standing still, empty (no crew or passengeres at all are allowed to be on board) and have damage. Further, the mechanic cannot fix any vehicle below 10%, nor can he/she fix any vehicle above 60% (I might lower that even further, as I want repair stations/trucks to do the complete job), and ofcourse the mechanic can only repair up to 60% damage (or what ever value I decide in the future).. I'm even thinking of adding a 'tools & resources' counter that when reaches zero (but can be restocked at base), they can't do any more field repairs at all. Then again, thats something for the future.. Since addActions are removed when the player is killed, I've used a "killed" eventHandler to run a script that evaluate which actions the killed player is entitled to have, and re-attach them to him/her. BUT! As for the mechanic script, that can only be run once, since it is a continiously running script that checks the player if he/she is near a damaged vehicle - and if so - it adds the addAction (or removes it if the criteria is no longer fulfilled). This means that when a player dies, this script IS already running, and is denied a re-execution. (This is not part of the problem, just some background info to show how I'm thinking..) I've tried to create a diagram to give an overview of the overall process; The green box is the code that I'm having problem with for now (haven't started on the other addAction scripts). (PS! Not all players have actions, and some even have 2 or more.) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= I'll split up the code (the green box) and try to explain my intentions; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (bRoleMechanicRunning) exitWith {false}; bRoleMechanicRunning = true; This is the part that makes sure the code is only run once (I hope).. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plyr = _this select 0; _aaMechanic = 0; Line 1; Getting the player ID. Line 2; Declaring and setting the addAction ID variable. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {true} do { Looping code start... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_NearestVehicles = nearestObjects [_plyr, ["landvehicle", "Air", "Ship"], 10000]; _NearestVehicle = _NearestVehicles select 0; _NVSpeed = speed _NearestVehicle; _NVCrew = count crew _NearestVehicle; _NVDamage = damage _NearestVehicle; First line; This is something I haven't really gotten around to really test properly since the code in general malfunctions, but that is not really the issue of this thread anyway. I'll do more research on which function is the best one to detect nearest vehcile of any type later. If I need help, I'll create a new thread.. Second line; This just picks the first one of the collection of vehicles gathered from the first line. But, if I can recall correctly I've read somewhere that the first element in the nearestObject list is not necessarily the closest unfortunatly, but I'll do a research on that later.. (and create a new thread on the issue if necessary). Third, fourth and fifth lines; Gathers necessary information about that vehicle that needs to be in a certain state in order for the mechanic to get the "repair vehicle" option. First, the vehicle needs to stand still, second, no people are allowed onboard (safety hazard ) and last but not least, it'd be nice if there where damage that could be fixed.. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((_NVSpeed == 0) and (_NVCrew == 0) and (_NVDamage >= 10) and (_NVDamage <= 59) and (_aaMechanic == 0)) then {_NVAction = true} else {_NVAction = false}; This is where the main checking is being done; Is the speed zero (_NVSpeed == 0), AND is there nobody onboard (_NVCrew == 0), AND is the damage between 10 and 59 percent (_NVDamage >= 10) and (_NVDamage <= 59), AND the mechanic doesn't have the addAction menu yet (_aaMechanic == 0)? If all is true, then _NVAction is set to correct (the mechanic may be granted the "repair vehicle" option), otherwise _NVAction is false, and the mechanic aren't allowed the "repair vehicle" option. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((_NVAction) and (_aaMechanic == 0)) then {_aaMechanic = _plyr addAction ["Repair Vehicle", "res\bat\cli\plr\actions\mechanic.sqf", "", -999, false, true, "teamSwitch"]}; Here I'm checking to see if the mechanic may be granted that "repair vehicle" option (_NVAction), AND that he/she isn't already posessing the option (_aaMechanic == 0). If both to be true, the "repair vehicle" option is added. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((!_NVAction) and (_aaMechanic > 0)) then {removeAction _aaMechanic; _aaMechanic = 0;}; Last but not least, check if the contitions are no longer true (!_NVAction), BUT he/she already have the "repair option". If both to be true, remove the option. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">sleep 0.5; Wait half a second, then redo the whole procedure... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> }; End of loop, return to top, and re-do the whole process... I hope that gives an image of how I'm thinking, and please, be my guest give me som constructive critisism feedback. I'm not a hardcore coder - especially when it comes to OFP / ArmA coding.. While my problem is no longer the while {true} do {};, it seem to have shifted focused on the if/then's instead - but still within the while/do block.. Seems that ArmA isn't exactly a pro in pinpointing where the problems lies.. I've checked and re-checked my code over and over, even testet the numerical content of numerical variables instead of testing them boolean-wise to see if that was the problem, but that was yet again a failed attempt.. I'm just about to discard the whole bloddy mechanic project as such... ZNorQ. Share this post Link to post Share on other sites
Doolittle 0 Posted September 14, 2007 I like to take the simple approach.... I would just give everyone the radio command of "Repair nearest" and when they use the command, then make the check to see if they have the ability to use the command or if there's even a vehicle nearby. I have a command in my mission called "Fix car" which anyone can use, and I leave it in the radio list. If you use it when you're not in a car, no big deal.. just give a message saying "You must be in a vehicle to use this command." Doolittle Share this post Link to post Share on other sites
ZNorQ 0 Posted September 14, 2007 I like to take the simple approach.... I would just give everyone the radio command of "Repair nearest" and when they use the command, then make the check to see if they have the ability to use the command or if there's even a vehicle nearby.I have a command in my mission called "Fix car" which anyone can use, and I leave it in the radio list. If you use it when you're not in a car, no big deal.. just give a message saying "You must be in a vehicle to use this command." Doolittle Hehe, well I like the difficult and narrow approach (geez, I sound like a preacher..). I do like it when the people who actually is supposed to use certain functions get it, and not the whole lot. Thanks for the tip, though. ZNorQ Share this post Link to post Share on other sites
ZNorQ 0 Posted September 16, 2007 OMG!!! At this point, I'm really pissed off! All the time (and I've kept on at it for a LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG time now!!! ), its not the while/do and if/then that was wrong - even though the damn faulty error messages said so - it was the removeAction that had an error!!!! This is what I had in the code: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">removeAction _aaMechanic; I forgot to put the object that the action is to be removed from, so I added _plyr infront of it, and now it works! I must say that this engine got a really crappy exception system, and I beg BIS to do something about this - atleast in ArmA 2! Anyway, now I know that I have to look elsewhere when trying to figure out what is wrong! Thanks to all of you guys who tryed to help me out anyway.. I'll just go cry in a corner now for having spend hours, upon hours, upon hours trying to figure out this damn error... ZNorQ Share this post Link to post Share on other sites
Doolittle 0 Posted September 16, 2007 Heh. Welcome to programming. I mean, I think you'll find what makes a good programmer is not someone who's really smart, but someone who has tons of patience. Doolittle Share this post Link to post Share on other sites
ZNorQ 0 Posted September 16, 2007 Heh. Welcome to programming. I mean, I think you'll find what makes a good programmer is not someone who's really smart, but someone who has tons of patience. Doolittle You know what, I totally agree with you, which whould make me a really poor programmer.. ZNorQ Share this post Link to post Share on other sites