[B]Button Function/Creation
[/B]
button2 = vgui.Create( "DButton", Form ) -- Creates a button
button2:SetSize( 100,30 ) -- Sets the size of the button
button2:SetPos( 63,70 ) -- Sets the position of the button reletive to the form
button2:SetVisible( true )
button2:SetText( "Join B1U!" )
button2.DoClick = function()
button1:SetVisible( true )
button2:SetVisible( false )
buttonleave:SetVisible( true )
LocalPlayer:SetTeam( 3 ) <<---- This is what i want to work
end
[B]The Error
[/B]
[ERROR] gamemodes/theuntitledgame/gamemode/cl_menu.lua:33: attempt to index global 'LocalPlayer' (a function value)
1. DoClick - gamemodes/theuntitledgame/gamemode/cl_menu.lua:33
2. unknown - lua/vgui/dlabel.lua:206
I have the menu in its own lua file ( it was in cl_init.lua but it didnt work out) I have tried testing the game in multiplier and single player and the error remains.
Your error message tells you [B]exactly[/B] what you are doing wrong. You're trying to index LocalPlayer, but local player is a function. You need to actually call the function.
LocalPlayer()
[editline]7th March 2014[/editline]
Read the documentation: [url]http://gmodwiki.net/Lua/Global/LocalPlayer[/url]
And btw, thats the wrong section
Go to the [URL="http://www.facepunch.com/forumdisplay.php?f=65"]Developer Discussion section[/URL]
[QUOTE=KmartSqrl;44163387]Your error message tells you [B]exactly[/B] what you are doing wrong. You're trying to index LocalPlayer, but local player is a function. You need to actually call the function.
LocalPlayer()
[editline]7th March 2014[/editline]
Read the documentation: [url]http://gmodwiki.net/Lua/Global/LocalPlayer[/url][/QUOTE]
function LocalPlayer( ply )
ply:SetTeam( 3 )
end
?
[QUOTE=biohazard518;44169083]function LocalPlayer( ply )
ply:SetTeam( 3 )
end
?[/QUOTE]
You need to [i]call[/i] the function, not [i]define[/i] it. This might bring you a bit closer to the goal you're trying to achieve:
[cpp]
LocalPlayer():SetTeam( 3 )
[/cpp]
[QUOTE=Alternative Account;44174939]You need to [i]call[/i] the function, not [i]define[/i] it. This might bring you a bit closer to the goal you're trying to achieve:
[cpp]
LocalPlayer():SetTeam( 3 )
[/cpp][/QUOTE]
i have tried this and my result is:
[ERROR] gamemodes/theuntitledgame/gamemode/cl_menu.lua:33: attempt to call method 'SetTeam' (a nil value)
1. DoClick - gamemodes/theuntitledgame/gamemode/cl_menu.lua:33
2. unknown - lua/vgui/dlabel.lua:206
[QUOTE=biohazard518;44175774]i have tried this and my result is:
[ERROR] gamemodes/theuntitledgame/gamemode/cl_menu.lua:33: attempt to call method 'SetTeam' (a nil value)
1. DoClick - gamemodes/theuntitledgame/gamemode/cl_menu.lua:33
2. unknown - lua/vgui/dlabel.lua:206[/QUOTE]
[b][url=http://gmodwiki.net/Lua/Classes/Player/SetTeam]Lua/Classes/Player/SetTeam[img]http://gmodwiki.net/favicon.ico[/img][/url][/b] only exists on the server. You're trying to call it on the client - that's why it's throwing an error at you.
[editline]9th March 2014[/editline]
You could use the [b][url=http://gmodwiki.net/Lua/Libraries/net]Lua/Libraries/net[img]http://gmodwiki.net/favicon.ico[/img][/url][/b] library (or something else) to send a message to the server to tell it to switch the player's team.
Are you blind or ...
[url=http://i.imgur.com/8ibzE3D.jpg][img]http://i.imgur.com/8ibzE3Dl.jpg[/img][/url]
[url=http://i.imgur.com/hd56P3x.jpg][img]http://i.imgur.com/hd56P3xl.jpg[/img][/url]
I would suggest learning to code Lua before trying to code Lua.
[QUOTE=Contron;44180262][b][url=http://gmodwiki.net/Lua/Classes/Player/SetTeam]Lua/Classes/Player/SetTeam[img]http://gmodwiki.net/favicon.ico[/img][/url][/b] only exists on the server. You're trying to call it on the client - that's why it's throwing an error at you.
[editline]9th March 2014[/editline]
You could use the [b][url=http://gmodwiki.net/Lua/Libraries/net]Lua/Libraries/net[img]http://gmodwiki.net/favicon.ico[/img][/url][/b] library (or something else) to send a message to the server to tell it to switch the player's team.[/QUOTE]
G! thanks so much :)
[editline]10th March 2014[/editline]
[QUOTE=Quark:;44181807]I would suggest learning to code Lua before trying to code Lua.[/QUOTE]
Well if i learn BY CODING i will run into these problems and they will give me a hard time but in the long run i will remember them and wont make the same mistakes...
Just because some people learn from a text book or class or video series doesn't mean its the correct way to learn I like learning by doing
[QUOTE=biohazard518;44185002]
Well if i learn BY CODING i will run into these problems and they will give me a hard time but in the long run i will remember them and wont make the same mistakes...
Just because some people learn from a text book or class or video series doesn't mean its the correct way to learn I like learning by doing[/QUOTE]
If you read the manual and do some real practice you're a lot less likely to run into simple issues like this.
[QUOTE=biohazard518;44185002]
Well if i learn BY CODING i will run into these problems and they will give me a hard time but in the long run i will remember them and wont make the same mistakes...
Just because some people learn from a text book or class or video series doesn't mean its the correct way to learn I like learning by doing[/QUOTE]
Learn how glua works, and then start coding
Sorry, you need to Log In to post a reply to this thread.