Hello,
I have this error in my console, but I'm not too sure what is happening: addons/myderma/lua/autorun/sh.lua:82: 'end' expected (to close 'if' at line 5) near '<eof>'
Here is my code:
[CODE]if (SERVER) then
end
if (CLIENT) then
local midW, midH = ScrW() / 2, ScrH() / 2
local function OpenEmergency()
local Emergency = vgui.Create ( "DFrame" )
Emergency:SetSize( 250, 250 )
Emergency:SetPos( midW - ( Emergency:GetWide() / 2 ), midH - ( Emergency:GetTall() / 2) )
Emergency:SetTitle( "Emergency Calls!")
local DermaButton6 = vgui.Create( "DButton" )
DermaButton6:SetParent( Emergency )
DermaButton6:SetText( "Robbery!" )
DermaButton6:SetPos( 130, 35 )
DermaButton6:SetSize( 100, 50 )
DermaButton6.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! There is a robbery in progress!" )
end
local DermaButton5 = vgui.Create( "DButton" )
DermaButton5:SetParent( Emergency )
DermaButton5:SetText( "Shooting!" )
DermaButton5:SetPos( 18, 35 )
DermaButton5:SetSize( 100, 50 )
DermaButton5.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I hear shooting!" )
end
local DermaButton4 = vgui.Create( "DButton" )
DermaButton4:SetParent( Emergency )
DermaButton4:SetText( "Call The S.R.U!" )
DermaButton4:SetPos( 130, 110 )
DermaButton4:SetSize( 100, 50 )
DermaButton4.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need the S.R.U!" )
end
local DermaButton3 = vgui.Create( "DButton" )
DermaButton3:SetParent( Emergency )
DermaButton3:SetText( "Call The Police!" )
DermaButton3:SetPos( 130, 185 )
DermaButton3:SetSize( 100, 50 )
DermaButton3.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need the police!" )
end
local DermaButton2 = vgui.Create( "DButton" )
DermaButton2:SetParent( Emergency )
DermaButton2:SetText( "Call A Fire Truck!" )
DermaButton2:SetPos( 18, 185 )
DermaButton2:SetSize( 100, 50 )
DermaButton2.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need a fire man!" )
end
local DermaButton1 = vgui.Create( "DButton" )
DermaButton1:SetParent( Emergency )
DermaButton1:SetText( "Call An Ambulance" )
DermaButton1:SetPos( 18, 110 )
DermaButton1:SetSize( 100, 50 )
DermaButton1.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need an ambulance!" )
end
local words = { "!request", "/request" }
local function ChatCommand( ply, text )
if table.HasValue( words, text ) then
ply:ConCommand( "request" )
return ""
end
concommand.Add( "request", OpenEmergency)
end
end[/CODE]
Thanks.
Learn to read error messages you didn't properly end something. You need another end to close the if statement.
[QUOTE=boxvader;49632397]WTF are you doing here??? Why do you have ends after all of your derma elements? That's what's causing the problem you have too many ends. Please learn how to read error messages they are not that hard to understand.[/QUOTE]
Did you even read the code? All of those ends after the element are to close the DoClick function...
@OP The indentation is a mess, but assuming concommand is to be outside the ChatCommand function, then add another end after "return" because you only closed the if statement, not the function.
At least it's what I could tell by indenting it on Sublime.
[code]
local words = { "!request", "/request" }
local function ChatCommand( ply, text )
if table.HasValue( words, text ) then
ply:ConCommand( "request" )
return ""
end
end
concommand.Add( "request", OpenEmergency)
end
end
[/code]
[QUOTE=McDunkable;49632771]Did you even read the code? All of those ends after the element are to close the DoClick function...
@OP The indentation is a mess, but assuming concommand is to be outside the ChatCommand function, then add another end after "return" because you only closed the if statement, not the function.
At least it's what I could tell by indenting it on Sublime.
[code]
local words = { "!request", "/request" }
local function ChatCommand( ply, text )
if table.HasValue( words, text ) then
ply:ConCommand( "request" )
return ""
end
end
concommand.Add( "request", OpenEmergency)
end
end
[/code][/QUOTE]
Read my edited post I kinda just glanced saw him running a console command and didn't think about it. Pretty sure his problem is that he didn't end the function OpenEmergency().
He didn't end line 5 "if (CLIENT)..."
He needs to place the end somewhere inside depending on what he wants to do.
I assume he doesn't want to add a "request" command each time ChatCommand is called, which is why I ended the ChatCommand function
[QUOTE=McDunkable;49632789]He didn't end line 5 "if (CLIENT)..."
He needs to place the end somewhere inside depending on what he wants to do.
I assume he doesn't want to add a "request" command each time ChatCommand is called, which is why I ended the ChatCommand function[/QUOTE]
No that's just how the erorr is interputed what he actually didn't end is the OpenEmergency() function. If you look he has ends after each derma element and when you get to the last one there should be another end there to end the function. That's what he needs to add. The error is interputed as the if client being open because the compiler goes down the list and utilizes the ends for each statement that needs to be ended, since it is one short it believe he failed to end the "if (CLIENT)" when in reality after looking at his code he really failed to end the OpenEmergency() function. Otherwise he is defining the chat command function inside of the open emergency function. TBH I am not sure why he is making a chat command function on the client anyway that is pretty useless.
[CODE]
if (CLIENT) then
local midW, midH = ScrW() / 2, ScrH() / 2
local function OpenEmergency()
local Emergency = vgui.Create ( "DFrame" )
Emergency:SetSize( 250, 250 )
Emergency:SetPos( midW - ( Emergency:GetWide() / 2 ), midH - ( Emergency:GetTall() / 2) )
Emergency:SetTitle( "Emergency Calls!")
local DermaButton6 = vgui.Create( "DButton" )
DermaButton6:SetParent( Emergency )
DermaButton6:SetText( "Robbery!" )
DermaButton6:SetPos( 130, 35 )
DermaButton6:SetSize( 100, 50 )
DermaButton6.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! There is a robbery in progress!" )
end
local DermaButton5 = vgui.Create( "DButton" )
DermaButton5:SetParent( Emergency )
DermaButton5:SetText( "Shooting!" )
DermaButton5:SetPos( 18, 35 )
DermaButton5:SetSize( 100, 50 )
DermaButton5.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I hear shooting!" )
end
local DermaButton4 = vgui.Create( "DButton" )
DermaButton4:SetParent( Emergency )
DermaButton4:SetText( "Call The S.R.U!" )
DermaButton4:SetPos( 130, 110 )
DermaButton4:SetSize( 100, 50 )
DermaButton4.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need the S.R.U!" )
end
local DermaButton3 = vgui.Create( "DButton" )
DermaButton3:SetParent( Emergency )
DermaButton3:SetText( "Call The Police!" )
DermaButton3:SetPos( 130, 185 )
DermaButton3:SetSize( 100, 50 )
DermaButton3.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need the police!" )
end
local DermaButton2 = vgui.Create( "DButton" )
DermaButton2:SetParent( Emergency )
DermaButton2:SetText( "Call A Fire Truck!" )
DermaButton2:SetPos( 18, 185 )
DermaButton2:SetSize( 100, 50 )
DermaButton2.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need a fire man!" )
end
local DermaButton1 = vgui.Create( "DButton" )
DermaButton1:SetParent( Emergency )
DermaButton1:SetText( "Call An Ambulance" )
DermaButton1:SetPos( 18, 110 )
DermaButton1:SetSize( 100, 50 )
DermaButton1.DoClick = function()
RunConsoleCommand( "say", "/lrequest Quick! I need an ambulance!" )
end
end -- There needs to be an end here
local words = { "!request", "/request" }
local function ChatCommand( ply, text )
if table.HasValue( words, text ) then
ply:ConCommand( "request" )
return ""
end -- This closes the if statement for checking the chat command
concommand.Add( "request", OpenEmergency)
end -- This closes the chat command function
end -- This closes the client check
[/CODE]
Now I can't use my con command? The code is all correct, no errors, but my console command has stopped functioning.
You need to define the con command outside of the chat command function that is why it doesn't work.
[QUOTE=boxvader;49632851]You need to define the con command outside of the chat command function that is why it doesn't work.[/QUOTE]
I'm using your example but it still does not work, I'm restarting Gmod quickly so, hope for the best...
Yes, I didn't fix the con command part for you though. You need to place it oustide of the chat command function in order to get it work. Place it right before the very last end.
You need to learn about defining things and what exists when you define it where. If you define a con command inside a function that con command will not exsist until that function is ran.
Ok, thank you.
[editline]29th January 2016[/editline]
Again, no console errors but the chat commands are no longer functioning.
[QUOTE=Gogson8;49632904]Ok, thank you.
[editline]29th January 2016[/editline]
Again, no console errors but the chat commands are no longer functioning.[/QUOTE]
You didn't hook them to anything. If it's client-side use OnPlayerChat, if server-side use PlayerSay
[QUOTE=bigdogmat;49632963]You didn't hook them to anything. If it's client-side use OnPlayerChat, if server-side use PlayerSay[/QUOTE]
This is correct you need to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSay]GM/PlayerSay[/url] to make a chat command.
Use playersay and send a netmessage to the client, which then runs the Derma function.
[QUOTE=bigdogmat;49632963]You didn't hook them to anything. If it's client-side use OnPlayerChat, if server-side use PlayerSay[/QUOTE]
OnPlayerChat doesn't actually work like it's supposed to.
[QUOTE=Promptitude;49635143]OnPlayerChat doesn't actually work like it's supposed to.[/QUOTE]
How so?
Sorry, you need to Log In to post a reply to this thread.