Home   Help Search Login Register  

Author Topic: Simple Function File Errors  (Read 495 times)

0 Members and 1 Guest are viewing this topic.

Lean Bear

  • Guest
Simple Function File Errors
« on: 28 Jul 2005, 13:27:38 »
I'm new to functions, but seem to have the basic idea. I've done quite a few functins files so I know normally what the problems are. The problem I have here is....I don't know what the problem is, so I can't fix it.

Here's the function:

Code: [Select]
private ["_timeDelay","_timeStep","_return"];

_timeDelay = _this select 0;
_timeStep = _this select 1;
Counter = 0;

while { Counter <= _timeDelay }
   do
   {
   if (GlobalV = true)
      then
      {
      _return = true;
      }
      else
      {
      _return = false;
      };
   Counter = Counter + _timeStep;
   };
_return

When it is called from a script running in the mission, it comes up with an error message - but it runs way off the page before the |#| comes up.

I know its probably between/in the if then else control and the end of the function. Because, whenI first wrote the sqf file, I put == in the conditional by mistake - and I meant <=. And when I did this, there was no problem, except that the rest of the function didn't happen :P

Maybe its simple, like I missed a semi-colon or something, but I reckon this way I'll know for sure.
« Last Edit: 28 Jul 2005, 13:28:25 by Lean Bear »

UNN

  • Guest
Re:Simple Function File Errors
« Reply #1 on: 28 Jul 2005, 13:39:05 »
You need to use == in If statements, but for booleans you dont need them at all:

Code: [Select]
  if (GlobalV)
      then
      {
      _return = true;
      }
      else
      {
      _return = false;
      };

But using a function to delay\count time is not a good idea. Or am I just reading to much into the variable names?

Lean Bear

  • Guest
Re:Simple Function File Errors
« Reply #2 on: 28 Jul 2005, 13:41:22 »
Of course! How stupid of me :P

Thanks a lot UNN :)

I'm afriad that yes, you are reading into those names a bit too much. They make sense to me, but they're not used to count time or delay it :P

The function is used a lot and the time I am dealing with here is only just above 0 seconds, so you'll see why I need a function to do it - a script would be too slow.

This functions merely checks if the global variable is set to true or not during that period of time (normally around 0.4 seconds) :)

edit

Hang on, you're right!

Why the heck am I using a function? I wrote a quick script to do the same thing, but with a time delay (which I couldn't do before in the sqf).

It goes something like this:

Code: [Select]
_timeDelay = _this select 0
_timeStep = _this select 1
Counter = 0

#Loop

if (Counter <= _timeDelay) then {goto "Loop2"} else {exit}

#Loop2

if (GlobalV) then {interupt = true; exit} else {interupt = false}
Counter = Counter + _timeStep
~_timeStep

goto "Loop"

Thanks for pointing that out UNN :)

The only worry I know have is, if 100 units use this at about the same time, will OFP be fast enough to handle it? (And, will there be lag?) :-\
« Last Edit: 28 Jul 2005, 15:53:31 by Lean Bear »