Home   Help Search Login Register  

Author Topic: Sea Level Altitude Function Problem  (Read 675 times)

0 Members and 1 Guest are viewing this topic.

AngusHeaf

  • Guest
Sea Level Altitude Function Problem
« on: 22 Mar 2003, 23:53:21 »
I wrote an absolute sealevel function that, in my opinion, is more accurate than those that have come before. I know the scripting works but I'm trying to compartmentalize the code by making the sea level height script into a function.

To make a long story short, I'm at the end of my rope. I've looked at this function for hours and for some reason it refuses to work in function form. I'm using OFP 1.90 and I've read all the coding references but still I get this bizarre bool array error when I try to output the height value to a hint (for debugging purposes). I'm calling the function from a script file that calls the function twice (to get the height of two objects) then calculate the difference in height between them.

Check out my files and PLEASE see if there's something I just missed in the way of syntax! Many thanks to anyone who helps.

Download SeaLevel Height Test




AngusHeaf

  • Guest
Re:Sea Level Altitude Function Problem
« Reply #1 on: 23 Mar 2003, 00:09:25 »
Ok well, for those of you who don't want to download, unzip, and run the files I included I'll include the important stuff below... I realized a lot of you might have A.D.D.  ;)

MISSION.SQM
3 objects on map. 1 soldier (man), 1 jeep (jeep), 1 trigger (sealeveltrig). Man has "[man,jeep] exec "logic_getheightdif.sqs"" as INIT. This starts the script going.

INIT.SQS
Code: [Select]
sealeveltrig setPos [0,0,0];
GetHeight = preProcessFile "func_getheight.sqf"

LOGIC_GETHEIGHTDIF.SQS
Code: [Select]
; ***************************************
; Initialize input variables

_obj1 = _this select 0;
_obj2 = _this select 1;

sealeveltrig setPos [0,0,0];

; *************************************************************************************
; Find height of each of the two objects above sea level and then calc the difference

_obj1h = [_obj1] call GetHeight
_obj2h = [_obj2] call GetHeight

_dif = _obj1h - _obj2h

hint format ["Debug Info...\nObj1h: %1 \nObj2h: %2 \nDif: %3", _obj1h, _obj2h, _dif]

FUNC_GETHEIGHT.SQF
Code: [Select]
// *************************************************************************************
// Initialize variables

_obj = _this select 0;

// *************************************************************************************
// Find the height of the object

sealeveltrig setPos [0,0,0];
_3ddist = _obj distance ABS;
_a = (getpos _obj select 0)^2;
_b = (getpos _obj select 1)^2;
_2ddist = sqrt (_a + _b);

objh = sqrt ((_3ddist ^ 2) - (_2ddist ^ 2))

Somewhere along the way the function is not passing any values back to the script Logic_GetHeightDif.sqs. Or perhaps the function isn't running at all, it's damn hard to tell.

AngusHeaf

  • Guest
Re:Sea Level Altitude Function Problem
« Reply #2 on: 23 Mar 2003, 04:56:14 »
Code: [Select]
_3ddist = _obj distance ABS;
I did pick up a small error in my code. ABS should be sealeveltrig. However, this doesn't fix my problem with the "scalar bool array" error. Any ideas?

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Sea Level Altitude Function Problem
« Reply #3 on: 24 Mar 2003, 01:03:23 »
Well... from the (limited) amount I know about functions, you have to define all your variables at the start of your function.

This would be the reason you're getting all the bool array errors.

I suggest you grab someone else's function from the Ed depot and see how they define the variables ;)

Offline benreeper

  • Members
  • *
  • I'm a llama!
Re:Sea Level Altitude Function Problem
« Reply #4 on: 25 Mar 2003, 18:03:53 »
Go thru your script, find all of your variables and declare them at the very start of the function like:

private ["_var1", "_var2", "_var3", etc.]

You need to use the quotes. You have to declare the vars so that the preprocesser knows what to expect.  This is also a good idea in a regular OFP script also.  Declare all of your vars to a 0 value for it's type.

_array = []
_string = ""
_bool = false

I dont't think you need to do it with objects as I believe OFP assumes them.

Ben
Once I did this it got rid of a lot of a "scalar bool arrays"