NewTimer

Started by Cena, Apr 08, 2016, 02:29 PM

Previous topic - Next topic

Cena

can someone tell me how to use pstats[ plr.ID ].test in NewTimer. Thanx
Want To Meet Me Come #Cena At Lunet

Xmair


Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Cena

Like
 NewTimer("pstats[ player ].Mute", 1000, 1 "true");
 NewTimer("pstats[ player ].Mute", 5000, 1 "false");
Want To Meet Me Come #Cena At Lunet

ysc3839

I think NewTimer(function(){pstats[ player ].Mute=true}, 1000, 1); would be better.

Cena



using this

NewTimer(function(){pstats[ plr ].Mute}, 1000, 1 "true");
NewTimer(function(){pstats[ plr ].Mute}, 10000, 1 "true");
Want To Meet Me Come #Cena At Lunet

KAKAN

You're too good to do it.
You can't pass instance.
Use this:
NewTimer( @( bool, plrID ){ pstats[ plrID ].Mute = bool; }, 1000, true );
oh no

.

@KAKAN Yes you can pass instances if you know to implement it.

@ysc3839 You'd want to take the player instance as a argument because the index 'player' is not captured from the context of the parent function.
.

KAKAN

Quote from: S.L.C on Apr 08, 2016, 05:03 PM@KAKAN Yes you can pass instances if you know to implement it.
Probably the newbies won't get your snip. So, it's better for 'em to use the NewTimer function.
And also, do you think that @Cena would be able to understand your snippet?
oh no

.

#8
Quote from: KAKAN on Apr 08, 2016, 05:28 PM
Quote from: S.L.C on Apr 08, 2016, 05:03 PM@KAKAN Yes you can pass instances if you know to implement it.
Probably the newbies won't get your snip. So, it's better for 'em to use the NewTimer function.
And also, do you think that @Cena would be able to understand your snippet?

But it works just like the example you gave. Except if he tries that on the default NewTimer it won't work because it expects a string and not a function object. Did you just forgot what you recommended?

Quote from: KAKAN on Apr 08, 2016, 03:49 PMYou're too good to do it.
You can't pass instance.
Use this:
NewTimer( @( bool, plrID ){ pstats[ plrID ].Mute = bool; }, 1000, true );

How complicated is this compared to what you recommended? Except this one actually works.
_Timer.Create( @( bool, plrID ) (pstats[ plrID ].Mute = bool), 1000, 1, true, player.ID );
For example... You included {} curly braces in a lambda. You specified a function object as the name of the function. You forgot to specify the number of times the timer should execute. You forgot to add the player ID to the timer parameters/arguments.

And also something I've omitted for the sake of simplicity is to check if that player still exists after 1000ms. Because he could easily disconnect during that time and then you'd modify a player that doesn't exist. Thus... cause an error.
.