Koni 1 Posted September 18, 2011 I have my little chase script, but Instead of making it specific to a certain unit, then having to make a few of the same scripts but specific to each unit that needs it, how can I make it so the script dosen't name a unit, just have it work on any unit that activated it, if you get my drift ? while{true} do { (unitname) domove (position player); sleep 5; }; Edit: fixed it. _x = _this; while{true} do { (_x) domove (position player); sleep 5; }; Share this post Link to post Share on other sites
Muzzleflash 108 Posted September 18, 2011 Might wanna choose another variable name than '_x'. Not that it won't work but it primarily used in loops. You should change your while into this perhaps in case something happens to the unit it doesn't need to run anymore: while {!isNull _x && alive _x} do { Share this post Link to post Share on other sites
Koni 1 Posted September 18, 2011 (edited) Might wanna choose another variable name than '_x'. Not that it won't work but it primarily used in loops.You should change your while into this perhaps in case something happens to the unit it doesn't need to run anymore: while {!isNull _x && alive _x} do { I used _x because it is a loop, isn't it ?, as it's meant to be updating the players position every 5 seconds, to keep the chase up if _x is out of firing range and the players running for his life. ok, It makes good sense to stop the script when the unit dies, so I changed the script to this, have I done it right ? _x = _this; while {!isNull _x && alive _x} do { (_x) domove (position player); (_x) dofire player; sleep 5; }; because it's now throwing this error up Error !isNull Type Array, expected object,group,display] and the unit that executes the script no longer chases player. Edited September 18, 2011 by Koni Share this post Link to post Share on other sites
Muzzleflash 108 Posted September 18, 2011 (edited) Typically you don't make _x itself but use it through loop constructs, like forEach. I though that _x was a unit not an array. This should do it then: _x = _this; while { {alive _x && !isNull _x} count _x > 0} do { _x domove (position player) _x dofire player; sleep 5; }; Actually this example is a very good example of why you typically don't use _x yourself. Look in the while condition now. We use the CODE count ARRAY construct where each item from array is assigned to _x inside the code. If you aren't careful you might think that the _x inside the code is the same as the one outside. Compare it with this: _units = _this; while { {alive _x && !isNull _x} count _units > 0} do { _units domove (position player) _units dofire player; sleep 5; }; Edited September 18, 2011 by Muzzleflash Share this post Link to post Share on other sites
Koni 1 Posted September 19, 2011 Sorry, I may be causing confusion here. The way I made the script, _x is meant to be refering to the AI unit that detects the player and activates the script. When a unit that needs to chase the player activates the script I'm using this in the trigger. nul = [unitname] execVM "scripts\chase.sqf"; so _x is meant to be the unit that activates the script. Share this post Link to post Share on other sites
Muzzleflash 108 Posted September 19, 2011 Whatever you put before your spawn/call/execVM is what _this becomes. If you use: nul = [unitname] execVM "scripts\chase.sqf"; Then in chase.sqf: _this = [unitname]; If you instead do: nul = unitname execVM "scripts\chase.sqf"; Then _this = unitname; Share this post Link to post Share on other sites
Koni 1 Posted September 19, 2011 I got ya, thanks for clearing this up for me :) Share this post Link to post Share on other sites