paranoid_giraffe 14 Posted January 17, 2017 I am going to start off and say I've been trying to troubleshoot this code for several hours. Basically I have a market set up and I want a lot of AI to walk to different points of interest. Right now I have several flagpoles set up with variable names set as "POI_1" to "POI_15". The Code: _pois = [POI_1,POI_2,POI_3,POI_4,POI_5,POI_6,POI_7,POI_8,POI_9,POI_10,POI_11,POI_12,POI_13,POI_14,POI_15]; _rtime = 5; // random time for completion of waypoint _spd = (random (2))+1; // decude whether to walk to sprint _wpradius = 0; // waypoint radius _wp = (group (_this select 0)) addWaypoint [getPos (_pois select (random (count _pois))), _wpradius]; // create waypoint _wp setWaypointBehaviour "CARELESS"; _wp setWaypointCombatMode "BLUE"; _wp setWaypointCompletionRadius 3; _wp setWaypointForceBehaviour true; // _wp setWaypointPosition // _wp setWaypointScript if (_spd==1) then { _wp setWaypointSpeed "NORMAL"} else { _wp setWaypointSpeed "LIMITED"}; _wp setWaypointStatements ["true","_null = [this]execVM('ai_behavior.sqf');"]; _wp setWaypointTimeout [1, _rtime/2, _rtime]; _wp setWaypointType "MOVE"; Additionally, this is set up in the init box of the AI: _null = [this]execVM('ai_behavior.sqf'); And the problem is that this script works absolutely perfectly when there is one AI. I can set it to fast-forward and let it run for a very long time and the AI will walk to different flagpoles either walking or jogging to each, and the script will never hang up. The problem stems from having multiple AI. Then I get errors saying the following: '...ius = 0; _wp = (group (_this select 0)) |#|addWaypoint [getPos (_pois select (random (count _pois))), _wpradius]; Error 0 elements provided, 3 expected File C:\Users\****\Documents\Arma 3 - Other Profiles\Giraffe%20PVT%2e\missions\black_market.pja305\ai_behavior.sqf, line 38 Ignore the fact that is says line 38 - I have a lot of comments at the top of the script. This is for a multiplayer mission. Thanks for reading. EDIT: Oh yeah, and this isn't for a "life" server. (I know that carries a negative stigma for many people.) It's for a new PvP gamemode I am working on. EDIT2: CORRECTED CODE Spoiler _pois = [POI_1,POI_2,POI_3,POI_4,POI_5,POI_6,POI_7,POI_8,POI_9,POI_10,POI_11,POI_12,POI_13,POI_14,POI_15]; _rtime = 5; // random time for completion of waypoint _spd = (random (2))+1; // decude whether to walk to sprint _wpradius = 0; // waypoint radius _wp = (group (_this select 0)) addWaypoint [getPos (selectRandom(_pois)), _wpradius]; // create waypoint _wp setWaypointBehaviour "CARELESS"; _wp setWaypointCombatMode "BLUE"; _wp setWaypointCompletionRadius 3; _wp setWaypointForceBehaviour true; if (_spd==1) then { _wp setWaypointSpeed "NORMAL"} else { _wp setWaypointSpeed "LIMITED"}; _wp setWaypointStatements ["true","_null = [this]execVM('ai_behavior.sqf');"]; _wp setWaypointTimeout [1, _rtime/2, _rtime]; _wp setWaypointType "MOVE"; Share this post Link to post Share on other sites
theend3r 83 Posted January 17, 2017 (_pois select (random (count _pois))) is wrong. You need to floor it. Change it to selectRandom _pois else you could get 14.5 which rounds to 15 which doesn't exist. Share this post Link to post Share on other sites
paranoid_giraffe 14 Posted January 17, 2017 It does? The wiki for "random" says that, provided a single number (n), it will provide a random int between 0 and n-1. Wouldn't that mean "random 15" provides 0-14? EDIT: better yet, just discovered "selectRandom" I'll use that as a substitute and get back to you. Share this post Link to post Share on other sites
theend3r 83 Posted January 17, 2017 3 minutes ago, paranoid_giraffe said: It does? The wiki for "random" says that, provided a single number (n), it will provide a random int between 0 and n-1. Wouldn't that mean "random 15" provides 0-14? No, it doesn't. random 1 produces things like 0.3, 0.8875, 0.9889...etc. Random 15 can give you 14.5 just fine. Edit: Where exactly does it say that? Share this post Link to post Share on other sites
mrcurry 514 Posted January 17, 2017 6 minutes ago, paranoid_giraffe said: It does? The wiki for "random" says that, provided a single number (n), it will provide a random int between 0 and n-1. Wouldn't that mean "random 15" provides 0-14? EDIT: better yet, just discovered "selectRandom" I'll use that as a substitute and get back to you. random provides a number with decimals. Use floor random 15 to get correct indexes. Count-1 will work but will give you a uneven distribution if that bothers you. Share this post Link to post Share on other sites
paranoid_giraffe 14 Posted January 17, 2017 Just now, theend3r said: No, it doesn't. random 1 produces things like 0.3, 0.8875, 0.9889...etc. Random 15 can give you 14.5 just fine. I think this may be a classic case of not enough sleep. The example clearly shows "floor random 10", not "random 10". Okay, I am not going insane. I'll get back to you on the selectRandom's performance after I let it run for a bit Share this post Link to post Share on other sites
paranoid_giraffe 14 Posted January 17, 2017 AH. So the random indices were breaking the addWaypoint. Thank you! Corrected code: _pois = [POI_1,POI_2,POI_3,POI_4,POI_5,POI_6,POI_7,POI_8,POI_9,POI_10,POI_11,POI_12,POI_13,POI_14,POI_15]; _rtime = 5; // random time for completion of waypoint _spd = (random (2))+1; // decude whether to walk to sprint _wpradius = 0; // waypoint radius _wp = (group (_this select 0)) addWaypoint [getPos (selectRandom(_pois)), _wpradius]; // create waypoint _wp setWaypointBehaviour "CARELESS"; _wp setWaypointCombatMode "BLUE"; _wp setWaypointCompletionRadius 3; _wp setWaypointForceBehaviour true; if (_spd==1) then { _wp setWaypointSpeed "NORMAL"} else { _wp setWaypointSpeed "LIMITED"}; _wp setWaypointStatements ["true","_null = [this]execVM('ai_behavior.sqf');"]; _wp setWaypointTimeout [1, _rtime/2, _rtime]; _wp setWaypointType "MOVE"; This was a simple and embarrassing case of bad math and being unable to count. Thank you! Share this post Link to post Share on other sites