OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: AngusHeaf 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 (http://www.mphasemedia.com/extranet/flashpoint/HeightDifTest.zip)
-
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
sealeveltrig setPos [0,0,0];
GetHeight = preProcessFile "func_getheight.sqf"
LOGIC_GETHEIGHTDIF.SQS
; ***************************************
; 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
// *************************************************************************************
// 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.
-
_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?
-
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 ;)
-
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"