Alright is there anyway to add a delay to input.IsKeyDown because when i use it with a print statement it spams the console.
So don't use it in a print statement? Why would you want a delay on it? It counters the entire purpose of it
Where just using that to test if it works, it works but it registers multiple key presses
make a toggled local variable.
Toggle logic
[lua]-- Outside
local LastDown = false
-- Inside
if input.IsKeyDown() and !LastDown then
-- Pressed the key
LastDown = true
elseif !input.IsKeyDown() and LastDown then
-- Release the key
LastDown = false
end[/lua]
Timer logic
[lua]-- Outside
local systim = 0
local delay = 2 -- seconds before it can be triggered again
-- Inside
if systim <= SysTime() then
if input.IsKeyDown() then
systim = SysTime()+delay
-- Code
end
end
[/lua]
Basically input.IsKeyDown toggles my DFrame and because it spams its create duplicates and i crash.
I basically did what you said NaK but i got errors but i crashed before i could open my console
but it actually crashes me really fast almost instantly ,
Im off for the night thanks for the help but.
[QUOTE=Fresh~;51135831]Basically input.IsKeyDown toggles my DFrame and because it spams its create duplicates and i crash.
I basically did what you said NaK but i got errors but i crashed before i could open my console
but it actually crashes me really fast almost instantly ,
Im off for the night thanks for the help but.[/QUOTE]
My crystal ball have still not returned from repair.
Post your code as I got a feeling you're creating a DFrame each tick. (When you return)
-- snip --
Left page open for hours, duplicate reply.
input.IsKeyDown doesn't "spam", it tells you whether a key is down or not. As long as it's down, it returns true. If it's not, it returns false.
If you're checking whether it's down on every frame, and then do an action, it will do that action on every frame that the key is down.
[editline]1st October 2016[/editline]
Are there keypressed events in gmod? If so you'd want to use those.
Im on my laptop ATM cant go on my computer i will post the code tomorrow as for that last comment , i know but i was wondering if there was a workaround because the keypressed hooks dont work with Key Enums ...
[QUOTE=Fresh~;51136199]Im on my laptop ATM cant go on my computer i will post the code tomorrow as for that last comment , i know but i was wondering if there was a workaround because the keypressed hooks dont work with Key Enums ...[/QUOTE]
It's as simple as [lua]if input.IsKeyDown( KEY_ENUM ) and ShouldContinue then
ShouldContinue = false
-- Other stuff
end[/lua]
[editline]Jesus christs[/editline]
I just realized this is exactly what Nak said [QUOTE=Nak;51135809]Toggle logic
[lua]-- Outside
local LastDown = false
-- Inside
if input.IsKeyDown() and !LastDown then
-- Pressed the key
LastDown = true
elseif !input.IsKeyDown() and LastDown then
-- Release the key
LastDown = false
end[/lua][/QUOTE]
......
[QUOTE=Darkwater124;51136193]
Are there keypressed events in gmod? If so you'd want to use those.[/QUOTE]
Indeed, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerButtonDown]GM:PlayerButtonDown[/url]
i want to use KeyEnums
ive basically copied out the code Nak gave me but i crash
It just crashes me , i cant get errors because i crash...
[code]
local LastDown = false
if input.IsKeyDown( KEY_1 ) and !LastDown then
-- Pressed the key
LastDown = true
myFunction()
elseif !input.IsKeyDown( KEY_1 ) and LastDown then
-- Release the key
LastDown = false
end
[/code]
thats not how i did it at the start but ive resulted to just copying it because of all the crashes but i still crash..
[QUOTE=Fresh~;51136281]i want to use KeyEnums
ive basically copied out the code Nak gave me but i crash
It just crashes me , i cant get errors because i crash...
:snip:
thats not how i did it at the start but ive resulted to just copying it because of all the crashes but i still crash..[/QUOTE]
Are you defining `LastDown` outside of the hook you're using? Also, instead of doing all this you could try the hook I posted above, it'll only run once the player has pressed their key.
[QUOTE=bigdogmat;51136270]Indeed, [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/PlayerButtonDown"]GM:PlayerButtonDown[/URL][/QUOTE]
This crap is predicted which means it won't work at all on clients in singleplayer and in multiplayer you'll have to add prediction checks so it won't spam.
I really wish there was non-predicted clientside key press/release hook.
[QUOTE=mijyuoon;51136409]This crap is predicted which means it won't work at all on clients in singleplayer and in multiplayer you'll have to add prediction checks so it won't spam.
I really wish there was non-predicted clientside key press/release hook.[/QUOTE]
Oath, im going to take a break and see what happens tomorrow! ill try using the button down hook..
Sorry, you need to Log In to post a reply to this thread.