|
| 11 Feb 2016 01:50 AM |
So this is not a question on what it does but more like how it works.
For example:
local value = 0 function blah() if value == 0 then value = 1 end end
So how does switching the value of a random variable prevent the engine from running multiple times at once? |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 02:24 AM |
| The parts of the function that are inside the if statement will not execute until the function is called and the if statement is true. |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 02:26 AM |
your example doesn't work.
local value=0 function blah() if value~=0 then return end value=1 print"Hi, this function is debounced!" wait(2) value=0 end |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Feb 2016 06:51 AM |
| Your if statement will only pass if value == 0, but once it passes for the first time, you Change the value to 1, so it cannot run again. |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 06:53 AM |
Is deThruse not debounce
While thruse do DeThruse game.players.playeradded:connect(function(plr) local stats = Instance.new('IntValue', plr) stats.Name = 'leaderstats' local experience = Instance.new('IntValue', stats) experience.Name = 'EXP' experience.Value = 0 local level = Instance.new('IntValue', stats) level.Name = 'Level' level.Value = 0
experience.Changed:Connect(function() level.Value = math.floor(experience.Value / 1000) end) While thruse do local player = game.Players.LocalPlayer local leaderstats = player:WaitForChild('leaderstats') local level = leaderstats:WaitForChild('Level') local xp = player:WaitForChild('EXP') level.Changed:connect(function() if xp.Value < 1000 then level.Value = 1 end |
|
|
| Report Abuse |
|
|
WoolHat
|
  |
| Joined: 19 May 2013 |
| Total Posts: 1873 |
|
|
| 11 Feb 2016 09:41 AM |
Ranvlr, don't consider a career in being a comedian. It really just won't work for you.
As to the OP, debounce is like a lock. If something tries to use a block of code before the code is done executing, the request to use the code is denied. It's very often used in events.
Example: (not syntactically correct, because phone)
Debounce = true
Object.touched:connect:function(() If debounce == true then --is debounce true? First run it sure is. Debounce = false --revert Debounce to false. Bam! Nothing can pass the above if statement, unless... --blah Debounce = true -- something sets debounce back to true. Now the next time the is statement is running through, this code will be rerun End End) |
|
|
| Report Abuse |
|
|
| |
|