Jump to content

Timer vs getTickCount()


ds1-e

Recommended Posts

  • Scripting Moderators

Hey, as topic say, which is better to use? Let's say i need to check something every 5 seconds, unlimited times.

Will be better to use setTimer, every 5 seconds, and unlimited executes or check that in OnClientRender, like: my_variable == true then getTickCount() and do my stuff?

 

Link to comment
  • Moderators

1 active timer = setTimer

1 active timer + dx countdown = getTickCount

500+ active timers = (getTickCount or 1 global setTimer )

passive timers = getTickCount

 

It depends on the quantity, precision and the functionality you want to use next to it.

 

And yes with onClientRender you have to mind reducing the check amount. I can send you an example how I build my global lua timer, if you want.

 

 

Edited by IIYAMA
  • Like 1
Link to comment
  • Scripting Moderators
1 hour ago, IIYAMA said:

1 active timer = setTimer

1 active timer + dx countdown = getTickCount

500+ active timers = (getTickCount or 1 global setTimer )

passive timers = getTickCount

 

It depends on the quantity, precision and the functionality you want to use next to it.

 

And yes with onClientRender you have to mind reducing the check amount. I can send you an example how I build my global lua timer, if you want.

 

 

Why not. In total i will have less than 5 time task. (all of them will be active if needed - only.)

local painTick = getTickCount()

-- OnClientRender

if playerTable.player.pain then -- only if boolean == true
	if getTickCount() - painTick > 3000 then
		painTick = getTickCount()
		-- do my stuff.
		end
	end
end

 

Edited by majqq
Link to comment
  • Moderators
2 hours ago, majqq said:

Why not. In total i will have less than 5 time task. (all of them will be active if needed - only.)


local painTick = getTickCount()

-- OnClientRender

if playerTable.player.pain then -- only if boolean == true
	if getTickCount() - painTick > 3000 then
		painTick = getTickCount()
		-- do my stuff.
		end
	end
end

 

 

Because the addEventHandler + "onClientRender" will use more memory than a timer. Unless you have already attached an addEventHandler . Then it is more or less two function call's every frame vs a timer.

 

 

Link to comment
  • Scripting Moderators
15 minutes ago, IIYAMA said:

 

Because the addEventHandler + "onClientRender" will use more memory than a timer. Unless you have already attached an addEventHandler . Then it is more or less two function call's every frame vs a timer.

 

 

It's already attached to onClientRender within render events.

Edited by majqq
  • Like 1
Link to comment
  • Scripting Moderators
On 03/06/2019 at 21:42, IIYAMA said:

Then it would be fine.

Hey, i would like to know if using (local) variables, have any affect on performance, in onClientRender.

For example. Code like this:

local table = {value = 12000}

-- onClientRender
local value = table.value
dxDrawText(value)

It's better than this? Or it doesn't really matter.

local table = {value = 12000}

-- onClientRender
dxDrawText(table.value)

 

Link to comment
  • Moderators
8 hours ago, majqq said:

Hey, i would like to know if using (local) variables, have any affect on performance, in onClientRender.

For example. Code like this:


local table = {value = 12000}

-- onClientRender
local value = table.value
dxDrawText(value)

It's better than this? Or it doesn't really matter.


local table = {value = 12000}

-- onClientRender
dxDrawText(table.value)

 

Using a variable in this case might boost a very little performance. But not in a way that it will matter too much.

A case where it will actually have a significant effect:

local table = {value = 12000}



-- onClientRender

local value = table.value

dxDrawText(value)
dxDrawText(value) -- boost !

 

These steps will be reduced to 1x instead of 2x.

(1. Using the table reference to find the table object. Not sure if this actually takes more time than a numeric value.)

2. Searching in the table. Which takes time.

 

 

  • Like 1
Link to comment
  • 1 month later...
  • Scripting Moderators
On 03/06/2019 at 18:07, IIYAMA said:

I can send you an example how I build my global Lua timer, if you want.

Hey, if you could send it, this would be nice. Besides, i need to ask about other thing. I am thinking if i should choose client or server for that.

I will use setTimer or getTickCount(), to make time function. First of all send trigger from server and later decrease it, each 1 minute. Here's the problem, because i don't know if i should decrease it on client, and send trigger to server, or simply do it on server-side (this is in setTimer case), about getTickCount() i am forced to do this on client anyways. I'm afraid if this is secure thing. I store all of data in tables (which are more secure than elementData, or i am wrong?), on server and client. Besides i've secured all of my triggers.

Link to comment
  • Moderators
1 hour ago, majqq said:

Hey, if you could send it, this would be nice. Besides, i need to ask about other thing. I am thinking if i should choose client or server for that.

I will use setTimer or getTickCount(), to make time function. First of all send trigger from server and later decrease it, each 1 minute. Here's the problem, because i don't know if i should decrease it on client, and send trigger to server, or simply do it on server-side (this is in setTimer case), about getTickCount() i am forced to do this on client anyways. I'm afraid if this is secure thing. I store all of data in tables (which are more secure than elementData, or i am wrong?), on server and client. Besides i've secured all of my triggers.

I will send it you, when I am back from my holiday. Please send me a reminder during the coming weekend.

 

Elementdata is indeed something with more risks. Clients can edit element data from each element, no restrictions. Potential risks: cheat engine stuff, custom cached scripts loaded with loadstring, staff with executed command rights and downloaded resources.

 

I don't know what exactly you are going to build, but if the values shouldn't be edited on clientside, then don't edit them clientside.

The server is the teacher and all the students have to listen and shut up, until they have a question or suggestion. ?

 

 

 

Edited by IIYAMA
  • Like 1
Link to comment
  • Scripting Moderators
On 22/07/2019 at 18:17, IIYAMA said:

I will send it you, when I am back from my holiday. Please send me a reminder during the coming weekend.

 

Elementdata is indeed something with more risks. Clients can edit element data from each element, no restrictions. Potential risks: cheat engine stuff, custom cached scripts loaded with loadstring, staff with executed command rights and downloaded resources.

 

I don't know what exactly you are going to build, but if the values shouldn't be edited on clientside, then don't edit them clientside.

The server is the teacher and all the students have to listen and shut up, until they have a question or suggestion. ?

 

 

 

Hey :P

You told me to remind you about that, and here I am.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...