generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Debounce

Previous Thread :: Next Thread 
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
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
infortality is online. infortality
Joined: 28 May 2012
Total Posts: 942
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
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
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
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
11 Feb 2016 02:41 AM
I still dont understand
Report Abuse
cowsoncows is not online. cowsoncows
Joined: 11 Oct 2013
Total Posts: 2522
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
ranvlr2o50 is not online. ranvlr2o50
Joined: 30 Jan 2016
Total Posts: 46
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 is not online. 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
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
11 Feb 2016 01:17 PM
Thank you
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image