• Lua Accumulator
    4 replies, posted
How do I make so if I hold down a button a value incrases? I don't mean a = a + 1. I do believe that is called increment.
You could use [URL=http://wiki.garrysmod.com/?title=IN_KEYS#KEY_.2A_enums]IN_KEYS[/URL] and create a simple timer, which increases the value every 0,1 second, or something like that.
What will this be used for? It depends what you want it to do.
[lua]local speed = 5 -- increases by 5 every second that the button is held down local val = 0 hook.Add("Think", "Accumulate", function() if LocalPlayer():KeyDown(IN_RELOAD) then val = val + FrameTime()*speed end end)[/lua] Something like this maybe?
Yeah thanks!
Sorry, you need to Log In to post a reply to this thread.