• Variable resets when function is ran even if it's global
    2 replies, posted
I've got this cooldown snippet that checks for exactly that - cooldown. [code] function checkDelay () delay = CurTime() if delay <= CurTime() then print("No cooldown.") delay = CurTime() + 10 else print("Cooldown in effect.") end end [/code] But instead of a cooldown, I can spam USE constantly and the only output I get is "No cooldown.". The function is triggered by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/Use]ENT:Use[/url]. I checked what the variable value is when the function is ran, it always returns the current time. Maybe I'm not understanding how variables work in functions.
This is because at the top of the function you are setting delay to CurTime then checking if its <= CurTime which of course it will be. What you want to do is not set delay to CurTime at the top of the function.
[QUOTE=0V3RR1D3;52180474]This is because at the top of the function you are setting delay to CurTime then checking if its <= CurTime which of course it will be. What you want to do is not set delay to CurTime at the top of the function.[/QUOTE] Ah, okay. I see. Don't know how I didn't notice that.
Sorry, you need to Log In to post a reply to this thread.