Home   Help Search Login Register  

Author Topic: Function not working...  (Read 1240 times)

0 Members and 1 Guest are viewing this topic.

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Function not working...
« on: 13 Aug 2007, 01:24:38 »
Bah, I wrote a function to find a position that is not over water. Function looks like this:

Code: [Select]
private ["_logic","_goodPos","_pos"];

_logic = "Logic" camCreate [0,0,0];

_goodPos = false;

while {!(_goodPos)} do
{
_pos = [(_this select 0) + (random 200) - (random 200),(_this select 1) + (random 200) - (random 200),0];
_logic setpos _pos;
_goodPos = _logic call overwater;
};
deletevehicle _logic;
_pos

Overwater function looks like this:

Code: [Select]
/*--------------------------------------------------------------------
OverWater function -=- by snYpir (based on code by DKM-Rastavovich)

Returns true if the unit passed in is over the water. Code
ripped out of DKM-Rastavovich's DKMM_Choppers addon.

Returns false if the unit passed in is over the land.

Called with:

<name of unit> call OverWater

Requires:

* overwater.sqf to be preprocessed and present in the mission dir
* the line 'theorigin = "Logic" camcreate [0,0,0]' must be in init.sqs
----------------------------------------------------------------------*/

private ["_veh","_return","_absolute_height"];

_veh = _this;

_absolute_height = sqrt((theorigin distance _veh)^2 - (getpos _veh select 0)^2 - (getpos _veh select 1)^2);

if ( _absolute_height - (getpos _veh select 2) < 3 ) then
{
_return = true;
}
else
{
_return = false;
};

_return

But I keep getting an error from the loop in the first function, and I just can't see what it is :dunno:

I'm not the best writing functions TBH. Anyways, the basic idea is that I got a position [x,y,z], and I want to find a position randomly around that center with a radius on 200 m, that is not in the ocean...so if anyone got another solution for a function to pull this off, I'd like to hear that ;)

Also, it appears that the function works ok at start. The function is run several times without any problems, but after a while the error pops up, and then it pops up each time it is run.

Offline firecontrol

  • Members
  • *
Re: Function not working...
« Reply #1 on: 13 Aug 2007, 07:17:16 »
Not to sure here, but I think you may need to change all the _logic in your first function to something like logic1.

i.e.
Code: [Select]
private ["_goodPos","_pos"];

logic1 = "Logic" camCreate [0,0,0];

_goodPos = false;

while (!_goodPos) do
{
_pos = [(_this select 0) + (random 200) - (random 200),(_this select 1) + (random 200) - (random 200),0];
logic1 setpos _pos;
_goodPos = logic1 call overwater;
};
deletevehicle logic1;
_pos

Shot in the dark.. but it looks like Snypir's function requires an actual named object. Not a local variable in a different function.

Make sure you've heeded this advice, too:
* the line 'theorigin = "Logic" camcreate [0,0,0]' must be in init.sqs

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: Function not working...
« Reply #2 on: 13 Aug 2007, 10:14:46 »
Doh! How silly...I've set the function to exit the loop when the variable turns true, which means I've set the loop to exit once it finds a position that is to be considered in the ocean... ::)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Function not working...
« Reply #3 on: 15 Jan 2008, 20:16:24 »
Is that sqf conversion for ArmA or OFP?

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: Function not working...
« Reply #4 on: 29 Jan 2008, 08:59:54 »
OFP...I don't play ArmA... ::)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Function not working...
« Reply #5 on: 29 Jan 2008, 17:05:58 »
Made on-the-fly and untested, while it might work:

Code: [Select]
/*
 overwater.sqf
*/
private["_logic", "_sensor", "_pos", "_return"];
_pos = _this;
_logic = "Logic" camCreate [0,0,0];
_sensor = "sensor" camCreate [0,0,0];
_logic setPos _pos;
_sensor setPos _pos;
if (_logic distance _sensor > 1) then
{
   _return = false;
}
else
{
   _return = true;
};
deleteVehicle _logic;
deleteVehicle _sensor;
_return


Code: [Select]
/*
No_water_check.sqf
*/
private ["_pos", "_posini", "_rad", "_goodpos", "_ang"];
_posini = _this select 0;
_rad = 1;
_goodpos = false;
_ang = 0;
while {(_rad < (_this select 1)) && (!_goodpos)} do
{
   _pos = [(_posini select 0)+sin(_ang)*_rad, (_posini select 1)+cos(_ang)*_rad, 0];
   _ang = _ang + 10;
   if (_ang > 350) then
   {
      _ang = 0;
      _rad = _rad + 10;
   };
   _goodpos = [_pos] call overwater;
};

if (!_goodpos) then
{
   _pos = [0,0,0];
};
_pos

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re: Function not working...
« Reply #6 on: 31 Jan 2008, 01:11:18 »
Try this over water function. It returns a boolean TRUE if any part of a user defined circular area is over water and FALSE if the entire area is not over water. I also have a function that detects if an area is over a forest (only tested with BIS OFP maps), another that detects if an area is over and obstacle (buildings, vehicles, fences, trees, etc.). Also I have one the returns the average ground slope of an area. These were all part of resource that I did for making AI choppers land faster without predefining landing zones. I think you can still find the resource somewhere in the beta testing forum, if not I can send you all of these. For now, here is the overWater.sqf, hope it is useful for you.
« Last Edit: 31 Jan 2008, 01:18:54 by Raptorsaurus »