View previous topic :: View next topic |
Author |
Message |
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Fri Jul 25, 2014 1:25 pm Post subject: Restart timer |
|
|
Hey,
If I have a timer that updates GUI after 4 seconds.
And I update GUI manually after 2 seconds (means 2 more seconds until timer updates it), can I 'restart' the timer? if so, then how?
_________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Fri Jul 25, 2014 1:45 pm Post subject: |
|
|
Set Enabled to false and then back to true again
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Fri Jul 25, 2014 2:02 pm Post subject: |
|
|
Ok, thanks perfect.
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Jul 26, 2014 6:38 am Post subject: |
|
|
I'm also using "restart timer" thing very often.
For example I used this in my, very first version, table for DS II ("Items List" script):
Code: | function CEEdit1Change(sender)
if itemsTable==nil then return end
filteredTable = {}
local filter = UDF1.CEEdit1.Text
for i,v in ipairs(itemsTable) do
if v.name:upper():match(filter:upper()) then
filteredTable[#filteredTable+1] = v
end
end
UDF1.ShownItemsLabel.Caption = 'count: '..#filteredTable
fillList(UDF1.CEListBox1,filteredTable)
end |
CEEdit1 is used to filter out other items, those which doesn't match.
Because I didn't want another "OK" button, I called fillList function inside CEEdit1Change. This fillList function clears ListBox and then fills it again. It has one unpleasant effect: for every typed letter ListBox is refreshed. Sometimes those calls are stacked (user already typed in whole word very fast and list still will blink one or two times).
I resolved this problem by using timer:
Code: | if filterDelayTimer ~= nil then filterDelayTimer.destroy(); filterDelayTimer=nil end
filterDelayTimer = createTimer(nil,false)
filterDelayTimer.Interval = 500
filterDelayTimer.OnTimer =
function (t) t.Enabled=false; fillList(UDF1.CEListBox1,filteredTable) end
function CEEdit1Change(sender)
if itemsTable==nil then return end
filteredTable = {}
local filter = UDF1.CEEdit1.Text
for i,v in ipairs(itemsTable) do
if v.name:upper():match(filter:upper()) then
filteredTable[#filteredTable+1] = v
end
end
UDF1.ShownItemsLabel.Caption = 'count: '..#filteredTable
filterDelayTimer.Enabled=false
filterDelayTimer.Enabled=true
end |
The above is exactly "set Enabled to false and then back to true again". ListBox is refreshed with 500ms delay. I left only visual thing which is immediately refreshed: ShownItemsLabel
_________________
|
|
Back to top |
|
|
|