Loop function

Discussions about Coding and Scripting
Post Reply
Torax
Adept
Posts: 406
Joined: Fri Apr 20, 2012 6:38 pm
Personal rank: Master of Coop
Location: Odessa, Ukraine

Loop function

Post by Torax »

Code: Select all

var int b;
do{
	//spawn some stuff
	b++;
	}until(b = 10 );
}
Is it possible to make loop function like this to not spawn things nearly instantly? I mean i need to add some delay before each new other actor should be spawned and "b" increased. I tried to make some state with loop function and add "Sleep()" line but that didn't give any effect..

Loop function is only thing that can solve my problem.
Unreal. Alter your reality..forever...
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Loop function

Post by Higor »

Create a new actor subclass:

Code: Select all

class MyStuffSpawner expands Actor;

var() int SpawnCount;
var() float SpawnTimer;
var() class<actor> ClassToSpawn;
var() bool bInitiallyActive;

var int iSpawnCount;

auto state Spawning
{
Begin:
    sleep(0); //Sleep 1 frame before spawning stuff, let whoever created me to set my initial parameters
    if ( bInitiallyActive )
        iSpawnCount = SpawnCount;
    bInitiallyActive = True;
SpawnAgain:
    if ( iSpawnCount-- <= 0 )
         Goto('End');
    Spawn( ClassToSpawn).Instigator = Instigator;
    //Notify master actor we've spawned an object? can be used to relocate myself before next spawn
    sleep(SpawnTimer);
    Goto('SpawnAgain');
End:
//Post process spawn
// Call events, self-destruct or whatever
}

//Spawn AGAIN!!!!
event Trigger( actor Other, Pawn EventInstigator)
{
    Instigator = EventInstigator;
    GotoState('Spawning');
}

defaultproperties
{
     bInitiallyActive=True
     bHidden=True
}



All you have to do now is (example):

Code: Select all

local MyStuffSpawner mySpawner;
mySpawner = Spawn(MyStuffSpawner,,,NewLocation, NewRotation);
mySpawner.ThingsLeft = 10;
mySpawner.ClassToSpawn = class'RocketMk2';
mySpawner.SpawnTimer = 0.2;
Or you can just insert it on the map and trigger it.


And if I want to reuse this timer:
Torax
Adept
Posts: 406
Joined: Fri Apr 20, 2012 6:38 pm
Personal rank: Master of Coop
Location: Odessa, Ukraine

Re: Loop function

Post by Torax »

Thanks a lot:) i'l try this out, hope it will help. My idea where that problem raised is to spawn trail segments in a row with defined distance between them and controllable speed of appearance. This is details of subject. Mostly i need it to spawn projectile trail. Because projectile travels too fast to normally spawn trail from itself without breaks. So i decided to use delayed loop to make location of each next segment of trail similar to projectile position. Or nearly similar
Unreal. Alter your reality..forever...
Post Reply