Al Simmons 0 Posted December 12, 2006 Situation: Iam trying to create an Flashbang-sim addon, for this effect i want to create some small explosions ("ASFlash1" ammo that was created via config.cpp-addon) on the position of the flashbang ("ASFlashbang" ammo that was created via config.cpp-addon). Best way to solve this, is to create an "fired" eventhandler for the unit. Here my problems start. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_p = _this select 0 _b = _this select 4 ?_b != "ASFlashbang": exit ~0.5 _g = "ASFlash1" createVehicle [(GetPos _b select 0)+ random 5,(GetPos _b select 1)+ random 2,+0.01]; ~ 0.4 _g = "ASFlash1" createVehicle [(GetPos _b select 0)+ random 5,(GetPos _b select 1)+ random 2,+0.01]; ~ 0.3 _g = "ASFlash1" createVehicle [(GetPos _b select 0)+ random 5,(GetPos _b select 1)+ random 2,+0.01]; exit anyhow it dont works, i used the biki and all but no way. Error message <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">'_b= _this [#]select 4' error Nullteiler this is my eventhandler <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addeventhandler ["fired",{[_this select 0,_this select 4] exec "3b.sqs"}] So if someone has an idea how to fix that problem, please help me. Share this post Link to post Share on other sites
Big Dawg KS 6 Posted December 12, 2006 Because you used [_this select 0,_this select 4] to call your script, _this select 4 would be the 2nd object in the array, and you are no longer passing on the whole array, and thus in your script you would have to use _this select 1. If that doesn't make sense, I'll attempt to explain it. By default, the fired eventhandler passes on an array of 5 elements. This array would be the local variable _this in the code part of the eventhandler (the part in the {}'s), and would be the same thing as [_this select 0,_this select 1,_this select 2,_this select 3,_this select 4]. When you executed the script you pulled the unit (_this select 0) and the ammo (_this select 4) out and put it into a new array, so it would be [unit,ammo] exec "script". Now, in the script, you have a new local variable _this, you only passed on 2 elements, so in the script the _this variable would be equal to [unit,ammo]. So in order to retrieve the ammo, it would be the 2nd element in your _this array and thus you use _this select 1. So, ammo = _this select 1, since _this = [unit,ammo]. So in your script, you would need to set _b = _this select 1: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_p = _this select 0 _b = _this select 1 Or, you could just execute the script with a simple _this in place of the array, and it would be correct (as _this would be the same thing as [_this select 0,_this select 1,_this select 2,_this select 3,_this select 4], and you would pass all 5 elements on to the script). This might be a better idea, since if you ever need the other elements you can just define them in the script. Example: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addeventhandler ["fired",{_this exec "3b.sqs"}] I hope that's easy enough to understand. Share this post Link to post Share on other sites
Al Simmons 0 Posted December 12, 2006 @KyleSarnik Thx now it works Share this post Link to post Share on other sites