Home   Help Search Login Register  

Author Topic: Functions and why I need a delay...  (Read 808 times)

0 Members and 1 Guest are viewing this topic.

EXS

  • Guest
Functions and why I need a delay...
« on: 16 Jul 2004, 19:37:29 »
Hi,

i have read snypr's function howto and have to say great work!
THANKS for this.

So here is my question:

I wrote 2 functions for a MP Mission, the first called "Add_Vehicle.sqf" adds Vehicle takes a parameter ["typ", position] and create a Vehicle of "typ" at "position". It returns an array: ["typ", position, object].

The second function is called "Del_Vehicle.sqf". It takes an array like "Add_Vehicle.sqf" - ["typ", position, object]. This function returns an array ["typ", position].

Both functions are working. The Problem is that I call them from a script called "respawn_vehicle.sqs" and it only works if I put an timer in front of the loop where I call any of these functions.
Code: [Select]
~1
#loop
...
[...,  ] call function;
...
goto "loop"

Why I have to put that timer???

I tryed a little bit and it works only if i put that timer!

But now when the mission start it hangs for a second (guess thats timers fault) and then the vehicles were created.

I have set the timer to 0.000000001 that worked too and it hangs not so much...

Do anybody know why or did I do something wrong?

mfg EXS

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Functions and why I need a delay...
« Reply #1 on: 16 Jul 2004, 20:14:24 »
You better put the ~1 inside the loop...

Now the loop loops as fast as your CPU possibly can loop it, and that will cause problems...
And in MP I would suspect that the problems would be even more likely to happen...

Functions are treated differently in OFP so they don't need (can't have) delay...

OFP engine may stop an sqs, if an operation which is more vital thus having higher CPU priority appears, and then continue it after that operation has been done so that fast loop may break up...

All of this is afaik 'n' s**t.... And I may just be talking holes in my head ::) :P
« Last Edit: 16 Jul 2004, 20:15:47 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

EXS

  • Guest
Re:Functions and why I need a delay...
« Reply #2 on: 16 Jul 2004, 20:44:10 »
But why I have to delay at all?

If I create the vehicles in the script instead call the function to do that it will work without a delay...

My next problem I can't get is as follows:

This is the first loop I wrote:
Code: [Select]
;script respawn_vehicles.sqs
...

;This loop will create 8 vehicles
~0.000000001
_i = 0;
#loop
_para = _vehicle_list select i;
_vehicle = [_param select 0, _param select 1] call Add_Vehicle;
_vehicle_list set [_i, _vehicle];
_i = _i + 1;
? (_i < 8) : goto "loop"


this works as expected but  because I don't like gotos, I changed it as follows:

Code: [Select]
;script respawn_vehicles.sqs
...

;This loop will create 8 vehicles
~0.000000001
_i = 0;
while "_i < 8" do {_param = _vehicle_list select _i; _vehicle = [_param select 0, _param select 1] call Add_Vehicle; _vehicle_list set [_i, _vehicle]; _i = _i +1;};
...
;rest of the script

And now there was an error message:
Code: [Select]
'|#|: _i = _i + 1;': Error Invalid number in expression

What is wrong with that? I don't get it? The script creates as expected the vehicles and very fast as I can say so far.

thanks EXS

------------------
Ok, I have tested the mission and the Error message didn't show up so I think I can ignore it...
« Last Edit: 16 Jul 2004, 23:15:25 by EXS »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Functions and why I need a delay...
« Reply #3 on: 16 Jul 2004, 23:24:02 »
Right...
I misread a bit there ::)

Actually, don't know about that delay thing...
But if bear in mind that OFP does act very strangely at times, especially with scripts, maybe that's somekind of a answer... :P

Quote
Ok, I have tested the mission and the Error message didn't show up so I think I can ignore it...
damned!!
And I had some great speculations all ready and written ;D

But anyhoo:
Are you sure you're quoted the script right??
'cause the |#|: would suggest that you had  :  instead of  ;  after the sentence _vehicle_list set [_i, _vehicle] ???

I just couldn't spot anything wrong with that :(
Unless your function also uses a variable called _i which is not listed in the private[] and does something with/to it...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

EXS

  • Guest
Re:Functions and why I need a delay...
« Reply #4 on: 16 Jul 2004, 23:35:30 »
I have checked that ":" instead of ";" 3 times and yes I have wrote ";".

I just saved as MP Mission and tested it and as I say the error doesn't come up, so I ignore it...

That delay thing iss very strange... but probably it worked so don't mind about that.

Maybe I do anywhere else a mistake, I'm a newbie...

thanks for help

EXS

---------------------

Ok after a night full of sleep and a restart, the error message is away definetly ...

« Last Edit: 17 Jul 2004, 07:18:19 by EXS »