• Local ply problems
    6 replies, posted
Still having some trouble how do i make ply local without getting this error [ERROR] lua/super_jump.lua:5: unexpected symbol near 'local' 1. unknown - lua/super_jump.lua:0 the code x = 0 function superJump(ply) if local ply:KeyDown(IN_DUCK) then repeat x = x+10 until local ply:KeyReleased(IN_DUCK) end end superJump() ****************************** I even got rid of them but to no avail ****************************** x = 0 function superJump(ply) if ply:KeyDown(IN_DUCK) then repeat x = x+10 until ply:KeyReleased(IN_DUCK) end end superJump() [ERROR] lua/super_jump.lua:5: attempt to index local 'ply' (a nil value) 1. superJump - lua/super_jump.lua:5 2. unknown - lua/super_jump.lua:12
Use the second snippet of code you posted. And make sure when you are callinging the function superJump you supply a player object as the 1st argument
You need to remember that player objects don't magically appear out of thin air.
[QUOTE=dingusnin;47470185]Use the second snippet of code you posted. And make sure when you are callinging the function superJump you supply a player object as the 1st argument[/QUOTE] Thank you for helping and i did what you said but i still got this error [ERROR] lua/super_jump.lua:4: attempt to index global 'ply' (a nil value) 1. unknown - lua/super_jump.lua:4 ************************** Heres the Code ************************** x = 0 function ply:superJump(ply) if ply:KeyDown(IN_DUCK) then repeat x = x+10 until ply:KeyReleased(IN_DUCK) end end superJump()
It looks like you are attempting to add a meta-method to the player object. to do this: -before you define the function, define ply to be the Player Metatable (ply = FindMetaTable( 'Player' ) ) -remove ply from your arguments -replace every 'ply' INSIDE the function with 'self'
[QUOTE=Pythonic;47470391]Thank you for helping and i did what you said but i still got this error [ERROR] lua/super_jump.lua:4: attempt to index global 'ply' (a nil value) 1. unknown - lua/super_jump.lua:4 ************************** Heres the Code ************************** x = 0 function ply:superJump(ply) if ply:KeyDown(IN_DUCK) then repeat x = x+10 until ply:KeyReleased(IN_DUCK) end end superJump()[/QUOTE] Read what chessnet said, you are calling this without any args ( that should be the player ) At the minute your function is really doing two things. First of all you are using a meta function ( i think this is the name ) as you have ply:superJump If you want to do that then do the following code [CODE] local Playermeta = FindMetaTable("Player"); function Playermeta:superJump() if self:KeyDown(IN_DUCK) then repeat x = x+10 until self:KeyReleased(IN_DUCK) end end concommand.Add("testmyjump",function(ply) ply:superJump() end) [/CODE] You would type testmyjump into your clients console, not the server. Edit: Dingu beat me to the punch. Don't just copy the code above, make sure you do it yourself so you learn something about how function args work, and meta tables too :)
[QUOTE=AIX-Who;47470680] [CODE] local Playermeta = FindMetaTable("Player"); function Playermeta:superJump() if self:KeyDown(IN_DUCK) then repeat x = x+10 until self:KeyReleased(IN_DUCK) end end concommand.Add("testmyjump",function(ply) ply:superJump() end) [/CODE][/QUOTE] FIFY
Sorry, you need to Log In to post a reply to this thread.