Rejn 0 Posted May 9, 2007 Ok here is a script I want to execute, the units spawn at gamelogic defcom1 within group def1. There are no units in def1 at present. This is all good and well, but when I try to run a second script same as this one except these variables of difference: creategroup: def2 group: def2 Position:defcom2 I get error type bool expected object |#| eventhandler etc... The script still goes ahead an executes.. Im not sure what the problem is... I've run multiple scripts were the units respawn when their killed however they tend to have 2 eventhandlers... I've also tried placing the event handler within the createunit init field... and still no diff. Is there something wrong in the code? p.s these units do not respawn. Thanks. Quote[/b] ]def1=creategroup resistance ~10 "SquadLeaderG" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.7, "SERGEANT"] ~1 "soldiergg" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.7, "Corporal"] ~1 "soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.7, "Corporal"] ~1 "soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 "soldiergmg" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 "soldiergat" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 "soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 "soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 "soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 "soldiergmedic" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec ""hide.sqs""}]", 0.5, "private"] ~1 def1 setbehaviour "aware" def1 setcombatmode "yellow" def1 setspeedmode "full" def1 enableattack false exit Share this post Link to post Share on other sites
Op4 BuhBye 0 Posted May 9, 2007 If Im reading this right you're using the eventhandler to exec a hide body script? Why dont you just create the group, name the units and use: ?!alive unit1 : unit1 exec "hide.sqs" and put it on a 5 second loop. Im not sure why you are using an event handler for this it seems over complicated to me. Anyway there are several things wrong with the above script the main one being you are calling a group when you should be calling a unit. Thats why you are getting the error. Share this post Link to post Share on other sites
Rejn 0 Posted May 9, 2007 I fixed the problem through a bit of trial and error. Firstly I removed the respawn units and all other eventhandlers... Im not sure if calling the group is wrong or not.. I wanted to generate a group name so I could spawn units into an already exsisting groupname where no prior units exsist. My fix has been thus: remove all the individual eventhandlers and use: EDIT : (readded select 0 ) {_x eventhandler ["killed",{_this select 0 exec "hide.sqs"}]} foreach units def1 This is a tad more efficient... Not sure how performance will go. Will repost if i have further errors. EDIT: IS AN EVENTHANDLER OR ?!(alive unitname) more efficient on pc performance?? Really need to know thanks Share this post Link to post Share on other sites
baddo 0 Posted May 9, 2007 Event handlers are in general believed to be more efficient but they can be misused so that performance can suffer greatly. An example of misusing event handlers is to execute a long and heavy script from a "fired" event handler every single time the event handler executes. Think about what happens when all the units that have this kind of event handler engage in a firefight with their weapons on automatic fire mode... In this kind of case it is not the fault of the event handlers if you don't get good performance, it is the fault of the person who scripted it so. I must add that you can in many cases put all the code directly into the event handler itself, so you need not to execute a script from the event handler. If your code is compatible with the function style scripting, you can try putting it in place of the code in the event handler line where you execute the "hide" script. I have a strong feeling that this must be more efficient than executing a script (but no research done to prove it). Share this post Link to post Share on other sites
Rejn 0 Posted May 9, 2007 Exellent ok thanks Well im not very good at scripting D: Also I fixed a mistake up their in my eventhandler for each units. Share this post Link to post Share on other sites
Rejn 0 Posted May 9, 2007 Well I managed to get the BSOD ... guess I went overboard :/ Had about 5 squads with eventhandlers and yer... :/ sigh... back to the drawing board.. What I think may of not helped was the fact that each squad had a (_x alive} count on it.. so that when the group had 0 units it would run the spawn script again... oh wells... Share this post Link to post Share on other sites
Op4 BuhBye 0 Posted May 9, 2007 Just write the "create unit" part(make sure you name the units), do what you have to do there and below it put this: #loop ~5 ?! alive unit1 : exec "body.sqs" ?! alive unit2 : exec "body.sqs" ?! alive unit3 : exec "body.sqs" ?! alive unit4 : exec "body.sqs" goto "loop" Every 5 seconds it will check if any are dead and exec the script. Share this post Link to post Share on other sites
Rejn 0 Posted May 10, 2007 Ok i've started using your suggestion of loop checking to see who is alive every 10 seconds via a loop... that should technically aleviate some of the system stress.. thanks Share this post Link to post Share on other sites
mr.Flea 0 Posted May 10, 2007 Quote[/b] ]"soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec "hide.sqs"}]", 0.5, "private"] understand me? Share this post Link to post Share on other sites
mr.Flea 0 Posted May 10, 2007 Quote[/b] ]"soldiergb" createUnit [position defcom1, def1,"this addEventHandler [""killed"",{_this exec "hide.sqs"}]", 0.5, "private"] understand me? hmm... sorry try, after create {_x addEventHandler ["killed",{_this exec "hide.sqs"}]}foreach units def1 Share this post Link to post Share on other sites
Rejn 0 Posted May 12, 2007 I have tried the last two suggestions however there seems to be problems when spawning 2 or more script loads of units all with this addeventhandler... ive just gone to naming the units to a1,a2,a3,a4,etc and placing a1 addevent.... etc Seems to work ok for now... for now... *crosses fingers* Share this post Link to post Share on other sites