• Using input.IsKeyDown in fretta
    5 replies, posted
Ok so I have a class, and in the class I have: [code] function CLASS:Think( pl ) if( input.IsKeyDown(32)) then pl:SetPos(pl:GetPos() + Vector(0,0,100)) end end [/code] And it says that 'input' is nil. How do I fix this.
The code needs to run clientside for it to work.
Ok, how do I get that to work? It needs to work only in that class and the classes are defined server side.
You classes should be defined in a shared file.
Im pretty sure they are, in shared.lua is where I have the teams set up.
I'm pretty sure that this won't work at all. player:SetPos(vector) only works sensibly serverside (or shared), while input.IsKeyDown(enum) only exists clientside. [url=http://wiki.garrysmod.com/?title=Player.KeyDown]This[/url] function is shared, the reason being that it uses the restricted number of keys that are available on both, whereas Client has access to every key the player can press (and some you normally can't). Also it's best if you use the ENUM name instead of the number, while the code looks shorter and has one less indexing operation if those numbers are changed you would have to fix the script and it is more readable when left as the enum. You want something like this [lua]function CLASS:Think( pl ) if( pl:KeyDown(IN_USE)) then pl:SetPos(pl:GetPos() + Vector(0,0,100)) end end[/lua]
Sorry, you need to Log In to post a reply to this thread.