sanctuary 19 Posted March 16, 2006 Hello, A script i thought to be simple to write is puzzling me as it is not working like i would want it to be. Here is the situation, i make it totally basic for easier understanding for this thread : Ingame i have a gamelogic named LOCAT1 I have a soldier with the following in its init line <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">SQUAD1=group this I have a script named first.sqs that has : <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[LOCAT1,SQUAD1] exec "second.sqs" exit the second.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dumloc = _this select 0 _dumsqud = _this select 1 "OfficerE" createUnit [_dumloc,_dumsqud,{this addeventhandler [{killed} , {[this,{OfficerE},_dumsqud,_dumloc] exec {third.sqs}}]},0.5,"LIEUTENANT"] exit Until there, everything work, the soldier is created where i want, it will join the group i want. But, after i kill this soldier, the third.sqs script is launched <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unito = _this select 0 _kindo = _this select 1 _groupo = _this select 2 _locao = _this select 3 _unito removealleventhandlers "killed" ~10 deletevehicle _unito ~1 _kindo createUnit [_locao,_groupo,{_unito addeventhandler [{killed} , {[_unito,_kindo,_groupo,_locao] exec {third.sqs}}]},0.5,"CORPORAL"] exit The unit is deleted after 10 seconds, then instead of being created again, there is an error, regarding the createunit line , too long in the screen for me to see exactly what OFP is trying to tell me. But, if i change <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_kindo createUnit [_locao,_groupo,{_unito addeventhandler [{killed} , {[_unito,_kindo,_groupo,_locao] exec {third.sqs}}]},0.5,"CORPORAL"] into <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_kindo createUnit [_locao,_groupo,{},0.5,"CORPORAL"] or <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_kindo createUnit [_locao,_groupo,"",0.5,"CORPORAL"] removing the line supposed to add the eventhandler , in case i got it wrong, the error occurs again, but this time , as the line is shorter i can read it : And there i am puzzled, as from what i wrote , there are no missing elements unlike what OFP is telling me, as in that case _kindo is supposed to be "OfficerE" , _locao is the game logic LOCAT1, _groupo is the group named SQUAD1 , so it should be the same as Quote[/b] ]"OfficerE" createUnit [LOCAT1,SQUAD1,{},0.5,"CORPORAL"] that would be working in a simpler script. Someone as an idea ? Share this post Link to post Share on other sites
UNN 0 Posted March 16, 2006 I don't think these two variables are being passed to thrid.sqs: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_groupo = _this select 2 _locao = _this select 3 The init event for your soldier is being called outside the script where you define those two local variables. So they don't exist when you call third.sqs. But as it's just the group and position, can't you do this instead: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dumloc = _this select 0 _dumsqud = _this select 1 "OfficerE" createUnit [_dumloc,_dumsqud,{this addeventhandler [{killed} , {[this,{OfficerE}] exec {third.sqs}}]},0.5,"LIEUTENANT"] exit <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unito = _this select 0 _kindo = _this select 1 _unito removealleventhandlers "killed" _groupo = Group _unito _locao = getpos _unito ~10 deletevehicle _unito ~1 _kindo createUnit [_locao,_groupo,{_unito addeventhandler [{killed} , {[_unito,_kindo] exec {third.sqs}}]},0.5,"CORPORAL"] exit Share this post Link to post Share on other sites
SoldierIsNotHistory 0 Posted March 16, 2006 From my point of view, this error is <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Error 0 element provided, 3 expected, x given Share this post Link to post Share on other sites
UNN 0 Posted March 16, 2006 I'm making the same mistake myself  _unito & _kindo as part of an event will not be valid, i think it should be: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dumloc = _this select 0 _dumsqud = _this select 1 "OfficerE" createUnit [_dumloc,_dumsqud,{this addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0)] exec {third.sqs}}]},0.5,"LIEUTENANT"] exit <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unito = _this select 0 _kindo = _this select 1 _unito removealleventhandlers "killed" _groupo = Group _unito _locao = getpos _unito ~10 deletevehicle _unito ~1 _kindo createUnit [_locao,_groupo,{This addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0)] exec {third.sqs}}]},0.5,"CORPORAL"] exit Edit : Fixed another typo Share this post Link to post Share on other sites
-)rStrangelove 0 Posted March 16, 2006 @Sanctuary: i think the position array _locao is empty. (_locao = _this select 3) Opf expects 3 values (x,y,z) but doesn't get them. Share this post Link to post Share on other sites
Garcia 0 Posted March 16, 2006 it is. When OFP says 0 elements are provided, it doesn't have the [x,y,z] coordinates... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _dumloc = _this select 0 _dumsqud = _this select 1 "OfficerE" createUnit [_dumloc,_dumsqud,{this addeventhandler [{killed} , {[this,{OfficerE},_dumsqud,_dumloc] exec {third.sqs}}]},0.5,"LIEUTENANT"] exit I'm suprised that even works, as you don't have any x,y,z position in the creation line. You've only got the name of the game logic, so instead of having a actual position, you've got a object... another problem you might run into is if the SQUAD1 group is "empty". If all units in the squad dies, I don't think you can create the unit. I didn't even know you can use the group name, thought it had to be the leaders (or any other unit in the group) name there. Share this post Link to post Share on other sites
sanctuary 19 Posted March 16, 2006 Thanks for the answer. That's what i feared. As if the eventhandler is unable to process correctly any kind of array or string took of it, it will force me to go to the old way i went for my previous missions that were using the same kind of createunit with their eventhandlers : making specific scripts for specific squads instead of this generic script idea. Quote[/b] ]_unito & _kindo as part of an event will not be valid, the _kindo and _unito in my example were valid in the case of no eventhandler are created in the third.sqs the "OfficerE" (_kindo) was passed from the script second.sqs to the third.sqs . The this (_unito) was passed too , as before the error, the unit was deleted as ordered in the third.sqs (deletevehicle _unito) But in the case of an eventhandler is given to the unit in the third.sqs, as you said they were not valid anymore. Quote[/b] ]_groupo = Group _unito Excellent, simple and effective to get a group passed from script to script while keeping them generic. Quote[/b] ]_locao = getpos _unito the problem with _locao is that it must be the original "spawning base" of this specific unit, in your idea it is now the location where the unit die. That's why to achieve my generic goal, i would have needed to get it from outside those eventhandlers then get passed from script to script. But if it is not possible to call a variable outside of an eventhandler, i imagine my idea is not possible, and i should use the same kind of specific script that worked in my previous missions instead of this generic one that i hoped to make scripts shorter. Something like first.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[LOCAT1,SQUAD1] exec "second.sqs" exit second.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dumloc = _this select 0 _dumsqud = _this select 1 "OfficerE" createUnit [_dumloc,_dumsqud,{this addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0),LOCAT1] exec {third.sqs}}]},0.5,"LIEUTENANT"] exit third.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unito = _this select 0 _kindo = _this select 1 _locao = _this select 2 _unito removealleventhandlers "killed" _groupo = Group _unito ~10 deletevehicle _unito ~1 _kindo createUnit [_locao,_groupo,{This addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0),LOCAT1] exec {third.sqs}}]},0.5,"CORPORAL"] exit this then is working perfectly, too bad this will force the creation of more scripts, but if that's the only way, i guess it is what it will be. Thanks again for your help guys, even if the out of eventhandler variable/array can't be passed, at last the other variable can now. Quote[/b] ]another problem you might run into is if the SQUAD1 group is "empty". If all units in the squad dies, I don't think you can create the unit. I didn't even know you can use the group name, thought it had to be the leaders (or any other unit in the group) name there. In OFP, as long as a squad name exist inside the mission, it can be used to spanw units even if everyone of this existing squad is dead, or even if at the beginning of the mission you use a deletevehicle on each of such squad member. Quote[/b] ]'m suprised that even works, as you don't have any x,y,z position in the creation line. You've only got the name of the game logic, so instead of having a actual position, you've got a object... In the createunit process, all you need is an object name , you can use [x,y,z] if you prefer, but as long it has an object name that exist on the map, it will work as with the createunit, OFP will get itself the x,y,z coordinates of this object. Share this post Link to post Share on other sites
Garcia 0 Posted March 16, 2006 Actaully, every time I've used a object name instead of the position of the object, I get the 0 elements provided error...so it's never worked for me or it's possibly just me doing something wrong...I dunno Share this post Link to post Share on other sites
UNN 0 Posted March 16, 2006 Quote[/b] ]the problem with _locao is that it must be the original "spawning base" of this specific unit, in your idea it is now the location where the unit die.That's why to achieve my generic goal, i would have needed to get it from outside those eventhandlers then get passed from script to script. I see, if the location will remain constant you can add it to the event handler as a string: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dumloc = _this select 0 _dumsqud = _this select 1 _Init=Format ["this addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0),%1] exec {third.sqs}]",getPos _dumloc] "OfficerE" createUnit [getpos _dumloc,_dumsqud,_Init,0.5,"LIEUTENANT"] exit <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unito = _this select 0 _kindo = _this select 1 _locao = _this select 2 _unito removealleventhandlers "killed" _groupo = Group _unito ~10 deletevehicle _unito ~1 _Init=Format ["this addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0),%1] exec {third.sqs}]",_locao] _kindo createUnit [_locao,_groupo,_Init,0.5,"CORPORAL"] exit Share this post Link to post Share on other sites
sanctuary 19 Posted March 17, 2006 (you just forgot a } in the 2 scripts) Thank you a lot UNN , it works perfectly now, it should be helpfull in the middle of my scripts to lower their amount. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dumloc = _this select 0 _dumsqud = _this select 1 _Init=Format ["this addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0),%1] exec {third.sqs}}]",getPos _dumloc] "OfficerE" createUnit [getpos _dumloc,_dumsqud,_Init,0.5,"LIEUTENANT"] exit <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unito = _this select 0 _kindo = _this select 1 _locao = _this select 2 _unito removealleventhandlers "killed" _groupo = Group _unito ~10 deletevehicle _unito ~1 _Init=Format ["this addeventhandler [{killed} , {[_This Select 0,TypeOf (_This Select 0),%1] exec {third.sqs}}]",_locao] _kindo createUnit [_locao,_groupo,_Init,0.5,"CORPORAL"] exit Share this post Link to post Share on other sites