Timer() v.s. check on Level.TimeSeconds

Discussions about Coding and Scripting
Post Reply
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Timer() v.s. check on Level.TimeSeconds

Post by MrLoathsome »

:?:
Suppose I have a mutator that uses function MutatorTakeDamage to spawn various effects...

Decided it needed a way to limit the number of effects being spawned based on time.
Have come up with 2 methods that both will work.
SpawnRate is a config var in the ini.

Here is the first:
(the log and else if (!bDoSpawn) log lines will be out of the prod. version...)

Code: Select all

function Timer()
{
	bDoSpawn = True;
	log("Timer time: "@Level.TimeSeconds);
}
.
.
.
	if ((ActualDamage > 0) && (bDoSpawn))
		{
... Do my stuff
			SetTimer(SpawnRate, True);
			bDoSpawn = False;
		}
		else if (!bDoSpawn) log("Spawn skipped by timer....");

I think that is the best solution, although I am pretty sure I could accomplish the same goal by just
doing a check on Level.TimeSeconds within the MutatorTakeDamage function.

Which method is going to execute faster ?
blarg
User avatar
anth
Adept
Posts: 257
Joined: Thu May 13, 2010 2:23 am

Re: Timer() v.s. check on Level.TimeSeconds

Post by anth »

Using a Timer slightly increases the native Tick processing time. Checking Level.TimeSeconds (and the interval check you will probably need) will slightly increase uscript processing time (about 4 extra opcodes per MutatorTakeDamage call). The load caused by both of these methods is neglectable but if you really need the fastest then go for the Timer.
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Timer() v.s. check on Level.TimeSeconds

Post by Feralidragon »

I think there's something that must be adressed as well:
Timer() is Tick dependent, which means that the real delay will depend on the game speed;
Level.TimeSeconds is always accurate no matter how slow or fast the game is: 1 second interval is really 1 second.

Basically if you want an accurate delay not dependent on the game speed, go with Level.TimeSeconds instead, or you can still use Timer(), but you will have to make the delay proportional on game speed: faster game, bigger delay.

But in case you want to make it game speed dependent, never use Level.TimeSeconds, your only option is really either Timer() or a controlled Tick.
User avatar
anth
Adept
Posts: 257
Joined: Thu May 13, 2010 2:23 am

Re: Timer() v.s. check on Level.TimeSeconds

Post by anth »

Level.TimeSeconds is updated in ULevel::Tick so it isn't 100% accurate either.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Timer() v.s. check on Level.TimeSeconds

Post by MrLoathsome »

Thanks for the replies. Good info from both of you.

The timer() method seems to be working perfect for my needs, so that is how it will stay.
blarg
Post Reply