Page 1 of 1

Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 6:27 am
by Dizzy
Unless I'm misunderstanding it, UScript's SetTimer() function sucks. It can't take function names as arguments so everything has to be done in a class-wide function called "Timer()".

Contrast this to most other languages which can set multiple timers for separate functions, for example JavaScript:
setTimeout("someFunction", 2000);
setTimeout("anotherFunction", 1000);

Is there a better way to use UScript's SetTimer() or is there a whole better way to establish timed functions?

Re: Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 9:58 am
by sektor2111
EXU pawns have some multiple timer code - it's a sort of trick, I'm not sure where it's used in pawn... but is a sample.
In other UE versions you have options to re-define this name. I mean multiple instances of a timer.
However I was heading for states last time using Sleep, and I like it.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 12:37 pm
by nogardilaref
Well, it's relatively "easy" to do a Javascript-like timer with targeted function names in this engine, but only through native C++ code (I believe even Shadow did something like that in his SDK).
Languages like Javascript have the perk of being very dynamic, but UScript is very rigid so doing anything like that is much harder unless directly supported through native code.

However, there are other rather "clean" ways to achieve multiple timers, by representing each timer through a different object, whether or not this object is an Object or an actual Actor.

Doing with just Actors is the most simple approach.
The principle itself is simple: you shift the responsibility of timing to another Actor, which then is able to run code to call back the kind of functions you want, which translates into something like this:

Code: Select all

class MyTimer extends Actor
{
    event Timer()
    {
        MyActor(Owner).SomeFunction();
    }
}

Code: Select all

class MyActor extends Actor
{
    function SetupFunctioOfSomeSort()
    {
        local MyTimer T;

        T = Spawn(Class'MyTimer', Self);
        T.SetTimer(5.0, True);
    }

    function SomeFunction()
    {
        ...
    }
}
Of course, this is just the basic gist for it.
This can be further developed into a more generic Timer class with more capabilities.

It could also be made with Objects instead, which would be a lot less resource intensive, but it would be a bit more complicated to do, since, unlike Actors, Objects aren't ticked, so you would need to have at least a central Actor, and have that Actor tick these Objects.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 2:47 pm
by JackGriffin
FWIW this was addressed in U227 and it's wonderful to use:
// Causes Timer() events every NewTimerRate seconds.
// @ InFunc, new in 227i: Causes an additional timer call with specified function name.
// Use 'All' to effect all timers.
native(280) final function SetTimer( float NewTimerRate, bool bLoop, optional name InFunc );
From the wiki explaining it
Added a new parameter for SetTimer function (optional name InFunc) where you can specify callback function which will also allow you to start multiple timers at once.
Code example care of Bleeder91

Code: Select all

function BeginPlay()
{
	SetTimer(0.5,False,'CallFus');
	SetTimer(1.0,False,'CallRo');
}

function CallFus()
{
	Log("Fus");
}
function CallRo()
{
	Log("Ro");
	SetTimer(0.1,True,'CallDah');
}
function CallDah()
{
	Log("Dah");
} 
Things like this are why I wish I could get more people to seriously consider moving over to Unreal and leave UT. Nearly every issue that gets posted here as a code bug/problem is already addressed there.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 5:46 pm
by nogardilaref
JackGriffin wrote: Things like this are why I wish I could get more people to seriously consider moving over to Unreal and leave UT. Nearly every issue that gets posted here as a code bug/problem is already addressed there.
Although I personally intend to do stuff there, sooner or later, the problem is the "game", and not the "engine".
The vast majority of players love UT for what it is, not what it's build on top of, and only a small portion of that even likes Unreal. They're completely different beasts.

The only way to even make way for what you're suggesting, would be to recreate UT in Unreal to some extent, a bit like Epic originally intended to do before deciding to make UT its own game.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 10:25 pm
by SilverSound
I tried moving to Unreal. The UT botpack was terrible and the game didn't feel at all like UT. Unless you can 1:1 everything while taking out bugs then good luck getting me to go there.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Fri Dec 01, 2017 11:14 pm
by sektor2111
Last time I was trying "MH" in some U227 server using Gold227. Client crashed in a heavy ambush with monsters because a lot of pupae were mooing around, probably exhausting all audio channels in those fascinating new drivers. NEVER HAPPENED in UT in any of my machines used - not gonna mention some lousy music files done for UT which do work in UT but they are crashing client when new audio drivers are loaded. If you say that is not true, then stop playing only CTF-Face and DM-Deck16][ and get deeper into gaming ground... yeah, rjmno1, I wish you luck with those things...
So to speak, when this 227 will be entirely ready as an UT replacement I will migrate there with lightning speed. So far I don't feel the need to bug myself.

So to refrain EXU has a sort of virtual multiple timer code and it is entirely USCRIPT. Ask politely help from Waffnuffly or UArchitect at UnrealSP.org.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Sat Dec 02, 2017 2:17 am
by JackGriffin
They are rewriting all the audio channels currently, removing overlaps and spots where they conflict.

Re: Anyone got a better SetTimer() function for UScript?

Posted: Sat Dec 02, 2017 6:07 am
by sektor2111
When their are ready I'll hit them, but if Higor will bring news for UT, then 227 might still wait.
The reality is that I got rid of timers as much as possible, I fired server playing those crapped things tweaked with NavAdder and then I got tired of playing, server was running as rock (collision hook disabled of course) using my tweaks. For now this is suffice. If 227 will have a more "flexible" Botpack and I expect it professionally fixed as for 21th century then I will backup and remove UT - because that thing still does include Accessed Nones, which made me surprised - still blabbering around. So far UT stays here... with my tweaked BotPack, lol. Btw I'm not using PlayerReplicationInfo with Timers - those times are gone...
As you can see I that one which I don't love timers as well so I went for replacements...
Reality was as follows:
I could see stuff getting stuck with 20 timers fired, but I did not see any game stuck with 200 monsters in different states. Because it looks like UE is way nice optimized for states rather than a crap-ton of timers running.