Jump to content
Sign in to follow this  
SoloZone

neasrestObjects issue

Recommended Posts

I have read and looked for an answer but I think I am just doing something simply wrong.

I keep getting this in the RPT and my hint is not showing. Error underfined variable in expression: _towerobj

this code is in an SQF executed via a trigger [player] exeVM "closebase.sqf". I know the sqf is executing as the first setmarkerpos is occurring. I am using this in MP and I am expecting the hint to provide the damage # of the tower near the player and broadcast it until he destroys it. Any help with second eye's would be greatly appreciated.:o

<closebase.sqf>

private ["_towerobj","_tdamage","_wreck","_player"];

_player = _this Select 0;

_towerobj = [];

"XMarker1" setmarkerpos (getpos dropZone);

_towerobj = nearestObjects [getpos _player,["Land_Cargo_Tower_V1_F"], 150] select 0;

while {alive _towerobj} do

{

"XMarker1" setmarkerpos (getpos _towerobj);

_tdamage = getdammage _towerobj;

FOCK_GHint = parseText format ["<t size='1.5' align='center'>%1</t>",_tdamage];

publicVariable "FOCK_GHint";

hint FOCK_GHint;sleep 1;

};

"ModuleExplosive_IEDUrbanBig_F" createVehicle position _towerobj;

_wreck = getPos _towerobj nearestObject "Land_Cargo_Tower_V1_ruins_F";

missionNamespace setVariable ["basewreck",_wreck];

publicVariable "basewreck";

deletevehicle baseWreck;

"XMarker1" setmarkerpos (getpos _towerobj);

Share this post


Link to post
Share on other sites

I'm not at my PC to test, but {alive _towerobj} will never return true since it's a building. You'll want to check it's damage instead like {((damage _towerobj) < 0.9)}

Share this post


Link to post
Share on other sites

Error is this line:

_towerobj = nearestObjects [getpos _player,["Land_Cargo_Tower_V1_F"], 150] select 0;

If there are no nearestObjects then it will return an empty array []

Therefore you are trying to select an element that doesn't exist

[] select 0 // throws an error

To avoid this, put a check to make sure some objects were returned

_array = nearestObjects [getpos _player,["Land_Cargo_Tower_V1_F"], 150];
if not (_array isEqualTo []) then {
    // your code
   _towerObj = _array select 0;
};

Edited by Das Attorney

Share this post


Link to post
Share on other sites
but {alive _towerobj} will never return true since it's a building.

Simply cannot be further from the truth. You can use alive command on buildings.

Share this post


Link to post
Share on other sites

@10bag I did test Alive function with this object and was working, I got back a true and false once it was destroyed. Thanks again

@das Attorney. aw man your right. I had the trigger in testing @ 175 but the nearestobjects @ 150, so it would toss me the []. See that, your catchnet led me to the code issue.. TANKS. Its working once I changed the trigger to 95 and left the nearestobjects to 100. I did use your code anyway as a double check.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×