Home   Help Search Login Register  

Author Topic: pre process sqf in addon - problem?  (Read 699 times)

0 Members and 1 Guest are viewing this topic.

Offline ScouseJedi

  • Members
  • *
pre process sqf in addon - problem?
« on: 12 Sep 2003, 18:45:57 »
I am making a trailer addon and would like to use a function in towing script.

If I pre process the function in the init function of the addon will it place multiple copies of the .sqf in RAM when more than one unit is active in the game.

ie, 6 trailers = 6 copies of the sqf?

I really dont want the mission makers to have to include a script.

(all the function does it go

if _x < 0 x=x+360
if _x > 360 x=x-360
return _x

but it takes a lot of sphegetti code out of the .sqs)

:)
'The truth is a beautiful and terrible thing, and should therefore be treated with great caution.'
Albus Dumbledore

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:pre process sqf in addon - problem?
« Reply #1 on: 12 Sep 2003, 20:57:46 »
I dont think it would make multiple copies. I think it would just overwrite itself as many times as it is run. IMagaine doing this in a script and you'll see what I mean,

myfunction = preprocessfile "myfunction.sqf"
myfunction = preprocessfile "myfunction.sqf"
myfunction = preprocessfile "myfunction.sqf"
myfunction = preprocessfile "myfunction.sqf"
myfunction = preprocessfile "myfunction.sqf"
myfunction = preprocessfile "myfunction.sqf"
myfunction = preprocessfile "myfunction.sqf"


Myfunction was just declared 7 times, but only one of them still exists.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline ScouseJedi

  • Members
  • *
Re:pre process sqf in addon - problem?
« Reply #2 on: 12 Sep 2003, 21:20:00 »
:) thanks

I was wondering if it was stored as

scjTrailer01.mysqf
scjTrailer02.mysqf

having it stored as mysqf means that missions could access it. Worth noting in the readme I suppose.

:)
'The truth is a beautiful and terrible thing, and should therefore be treated with great caution.'
Albus Dumbledore

Unnamed

  • Guest
Re:pre process sqf in addon - problem?
« Reply #3 on: 12 Sep 2003, 23:38:04 »
Scouse,

Did you have any problems with preprocessfile from the init event of an Addon? I could not get it to work :(

P.S  If your function is not to big, you could just add something like this to your init event without loading any external files:

Code: [Select]
Init="YourFunction={if _x < 0 x=x+360 ; if _x > 360 x=x-360 ; return _x}"
Then call YourFunction as normal.

Offline ScouseJedi

  • Members
  • *
Re:pre process sqf in addon - problem?
« Reply #4 on: 13 Sep 2003, 00:18:51 »
Well, I couldn't get it to work and then saw the flaw in my plan anyway. I moved my ideas on to something else. I probably have 3 times as much commented out code than actual working code now.

360 == 0 deg is a real pain in the bum.

I am making a trailer that should go only +- 60 degrees from the direction of the tow truck.

I can check to see if the trailer is in a valid position fine.

The problem comes when deciding which way it is wrong. If its >+60 I set it to +60. If its <-60 I set it to -60. Around VDir=180 and 360 it goes a little funny.



Im currently measuring the angle from the tow truck to the trailer using atan2 and comparing that to the TDir angle.

It works brilliantly as long as you are turning right :) When you go left it flickers in between correcting to +60 and -60 when the tow truck heading hits 0.

« Last Edit: 13 Sep 2003, 00:20:30 by ScouseJedi »
'The truth is a beautiful and terrible thing, and should therefore be treated with great caution.'
Albus Dumbledore

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:pre process sqf in addon - problem?
« Reply #5 on: 19 Sep 2003, 16:44:46 »
Quote
Did you have any problems with preprocessfile from the init event of an Addon? I could not get it to work
Yup, preprocessFile does not work within an addon. loadFile does, though.
Just make sure to remove all C-style comments (// /*) and any preprocessing
directives.

Quote
The problem comes when deciding which way it is wrong. If its >+60 I set it to +60. If its <-60 I set it to -60. Around VDir=180
and 360 it goes a little funny. Im currently measuring the angle from the tow
truck to the trailer using atan2 and comparing that to the TDir angle.
It works brilliantly as long as you are turning right  When you go left it flickers in between correcting to +60 and -60 when the tow
truck heading hits 0.
AFAIK, atan2 returns the angle in the range [-180, +180). To have it in the
range [0,360), add 360.

If you have problems with angle values above 360 or below 0, use the following:
_angle = _angle mod 360
_angle = 360 - _angle

This should always reduce any angle to the range [0,360) (i.e. 0 is included,
but 360 is not).