Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Adding delay to for-loop
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Adding delay to for-loop

Why use a for-loop? How about a timer loop?

PHP Code: (Select All)
int count 0;

void TimerLoop(string &in asTimer)
{
    
SetEntityActive(gNameOfSpiderEggs+""+countfalse);
    
SetEntityActive(gNameOfSpider+""+counttrue);
    
SetEntityActive(gNameOfBrokenSpiderEggs+""+counttrue);

    
count++; 
    
AddTimer(asTimerRandFloat(0.3f1.7f), "TimerLoop");


A for-loop will repeat the same action for a certain amount of times. It would work if Amnesia had any form of Thread.sleep(); function, but it does not as far as I'm aware of. A while-loop crashes you because it loops infinitely as long as the boolean question is accepted.

This Timer-loop is basically just an infintely looping timer. It repeats with a random delay to each iteration. Some of the variables I used can be replaced by the function versions (by that I mean the SetLocalVarInt instead of primitive int) if you prefer those.

To start the loop, just call
PHP Code: (Select All)
TimerLoop("loop"); 
To stop the loop, just call
PHP Code: (Select All)
RemoveTimer("loop"); 

You can add further checks to it so that it will only repeat for your specified Min and Max amounts, but those are simple if-statements. You can probably figure out what needs tweaking.

(This post was last modified: 11-05-2014, 12:28 PM by Mudbill.)
11-05-2014, 12:23 PM
Find


Messages In This Thread
Adding delay to for-loop - by Neelke - 11-05-2014, 08:57 AM
RE: Adding delay to for-loop - by Mudbill - 11-05-2014, 12:23 PM
RE: Adding delay to for-loop - by burge4150 - 11-06-2014, 06:43 PM
RE: Adding delay to for-loop - by Neelke - 11-06-2014, 10:10 PM



Users browsing this thread: 1 Guest(s)