OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: L!nk on 02 Mar 2008, 15:13:57

Title: The "#sleep 1;" error
Post by: L!nk on 02 Mar 2008, 15:13:57
This error happens a few seconds into my mission (#sleep 1;) and it selects a random sleep command in random files.

It has a major LAG effect and I get a CTD when I retry this mission.

The error also happens when I save the mission after I tried it.

The only way to stop it is to restart ArmA.

I only use .sfq syntax. Recently converted my skills from .sqs (this is possibly a issue)

All my scripts run fine and everyting works perfectly except for this one.

Read my http://www.ofpec.com/forum/index.php?topic=31021.0 (http://www.ofpec.com/forum/index.php?topic=31021.0) topic for a quote for how I use .sqf scripting.
Title: Re: The "#sleep 1;" error
Post by: h- on 02 Mar 2008, 16:01:49
Quote
Recently converted my skills from .sqs (this is possibly a issue)
Quite possible, I recently had the same problem with sqs scripts I used in OFP converted to sqf for ArmA.
The problem was that even though going through the scripts several times there were one or two occations where I had forgot to change exec to execVM which caused the problem.

Maybe it's the same in your case :dunno:
Title: Re: The "#sleep 1;" error
Post by: Wolfrug on 02 Mar 2008, 18:50:50
Make sure all your sleeps are actually sleeps : I keep mixing up my sleep 1; and ~1 if I happen to be in the middle of a conversion process. That sometimes causes problems.  :dunno: Also make sure as h- said that you're execvm'ing the .sqf properly!

Otherwise, we'll need a more complete quote of the code used to find the problem.

Wolfrug out.
Title: Re: The "#sleep 1;" error
Post by: L!nk on 02 Mar 2008, 19:10:16
Thats the thing. All of my scripts work perfectly. This isn't my first mission I made with .sfq files.

I recently started to use this type of coding methods. I call it Global functions...

Code: [Select]
hint "file lproccesed";

Link_RandomNum =
{
     _max = _this select 0;
     _min = _this select 1;

     while {player alive} do
     {
          sleep 1; // this is usually where I get my errors
          _num = (_min + (random _max));
          hint format ["%1",_num];
     };
     while {!(alive player)} do
     {
          sleep 1; // this is usually where I get my errors
     };
     [_max,_min] call Link_RandomNum;
};

This script is called like this:

Code: [Select]
[] execVM "file.sqf"; // first procces the file
sleep 1;
[10,2] call Link_RandomNum; // call a script in the file
Title: Re: The "#sleep 1;" error
Post by: Wolfrug on 02 Mar 2008, 22:14:27
Use Spawn instead of call -> can't normally have sleeps inside scripts called with call.  :good:

*waits for Mandoble & co. to come storming in with their objections*

Wolfrug out.
Title: Re: The "#sleep 1;" error
Post by: Mandoble on 02 Mar 2008, 22:44:48
I already replied with a code example in a different thread  :whistle:
Title: Re: The "#sleep 1;" error
Post by: L!nk on 03 Mar 2008, 17:53:43
I know, but them I asked you a question on it.

Why "spawn" and why "isNil" command.
Title: Re: The "#sleep 1;" error
Post by: Mandoble on 03 Mar 2008, 20:55:02
spawn (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=s#783) executes the provided code in parallel, calling script is not stopped while with call command the parent script is stopped until call code returns.

isNil (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=i#605) checks whether the provided variable is already defined or not. In your case, the code variable is global, so you dont need to define it over and over each time the script is executed.