• My code for a HUD isn't working
    108 replies, posted
Have you followed the Lua tutorial series on the Wiki? :/ Look at Line 25, you'll see that it expects another ) near (. So you look at the ( on line 25, and look where it needs a ) BEFORE that. So that'd be line 24, you missed a comma on SetTextPosition, probably after the 24.
[QUOTE=TheFallen(TF2);26516481][lua\autorun\client\huddistrict9.lua:25] ')' expected near '(' I don't understand what that means I checked the wiki and it didn't say what the error was, plus the game has reverted back to using the HL2 HUD.[/QUOTE] -snip- I am so stupid, rate me dumb
[QUOTE=Lord Ned;26516987]Have you followed the Lua tutorial series on the Wiki? :/ Look at Line 25, you'll see that it expects another ) near (. So you look at the ( on line 25, and look where it needs a ) BEFORE that. So that'd be line 24, you missed a comma on SetTextPosition, probably after the 24.[/QUOTE] I corrected the error, I'll do some more work on it tomorrow right now I'm heading to bed its getting late over here.
HUDDistrict9.lua:16: function arguments expected near '.' I checked my code and I found nothing wrong with it, no grammatical or spelling errors at all, heres the code: [lua]function HideHudBits( name ) if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" or name == "CHudSecondaryAmmo") then return false end end hook.Add( "HUDShouldDraw", "HideHudBits", HideHudBits ) surface.CreateFont( "D9 non-humans", 100, 400, false, false, "D9NonHumans" ) hook.Add ( "HUDPaint", "D9HudPaint", function() local hudPlayer = LocalPlayer() local hudHealth = hudPlayer:Health() local hudArmor = hudPlayer:Armor() local hud2nd = hudPlayer: surface.SetDrawColor( 128, 128, 128, 255) surface.DrawRect( 1, 34, 25, 25 ) surface.SetTextColo( 255, 0, 0, 255 ) surface.SetTextPos( 34, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( hudHealth ) surface.SetDrawColr(128, 128, 128, 255) surface.DrawRect(1, 24, 25, 25) surface.SetTextColor(255,0, 0, 255) surface.SetTextPos(24, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( HudArmor ) end [/lua]
[lua]local hud2nd = hudPlayer:[/lua] You missed out the last bit of this line [lua] surface.SetTextColo( 255, 0, 0, 255 )[/lua] [lua] surface.SetDrawColr(128, 128, 128, 255)[/lua] You spelt 'Color' wrong.
Fixed it however I got this: "lua: HUDDistrict9.lua:31: ')' expected (to close '(' at line 10) near '<eof>'" I hate this type of error so much its so difficult to figure out heres the line that it mentions: [lua]hook.Add ( "HUDPaint", "D9HudPaint", function()[/lua]
Again, if you properly tab your code it will be very easy to spot missing "end" statements. You missed a close ) on the end of the hook.Add line. [lua]function HideHudBits( name ) if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" or name == "CHudSecondaryAmmo") then return false end end hook.Add( "HUDShouldDraw", "HideHudBits", HideHudBits ) surface.CreateFont( "D9 non-humans", 100, 400, false, false, "D9NonHumans" ) hook.Add ( "HUDPaint", "D9HudPaint", function() local hudPlayer = LocalPlayer() local hudHealth = hudPlayer:Health() local hudArmor = hudPlayer:Armor() --local hud2nd = hudPlayer: --FINISH THIS LINE surface.SetDrawColor( 128, 128, 128, 255) surface.DrawRect( 1, 34, 25, 25 ) surface.SetTextColor( 255, 0, 0, 255 ) surface.SetTextPos( 34, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( hudHealth ) surface.SetDrawColor(128, 128, 128, 255) surface.DrawRect(1, 24, 25, 25) surface.SetTextColor(255,0, 0, 255) surface.SetTextPos(24, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( HudArmor ) end)[/lua]
[QUOTE=Lord Ned;26534378]Again, if you properly tab your code it will be very easy to spot missing "end" statements. You missed a close ) on the end of the hook.Add line. [lua]function HideHudBits( name ) if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" or name == "CHudSecondaryAmmo") then return false end end hook.Add( "HUDShouldDraw", "HideHudBits", HideHudBits ) surface.CreateFont( "D9 non-humans", 100, 400, false, false, "D9NonHumans" ) hook.Add ( "HUDPaint", "D9HudPaint", function() local hudPlayer = LocalPlayer() local hudHealth = hudPlayer:Health() local hudArmor = hudPlayer:Armor() --local hud2nd = hudPlayer: --FINISH THIS LINE surface.SetDrawColor( 128, 128, 128, 255) surface.DrawRect( 1, 34, 25, 25 ) surface.SetTextColor( 255, 0, 0, 255 ) surface.SetTextPos( 34, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( hudHealth ) surface.SetDrawColor(128, 128, 128, 255) surface.DrawRect(1, 24, 25, 25) surface.SetTextColor(255,0, 0, 255) surface.SetTextPos(24, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( HudArmor ) end)[/lua][/QUOTE] "lua: HUDDistrict9.lua:16: '=' expected near 'surface'" I don't think it means putting an equal sign where the period is but I don't know why it keeps getting errors like this. If this doesn't start working soon I might just give up on making it.
[QUOTE=TheFallen(TF2);26535387]"lua: HUDDistrict9.lua:16: '=' expected near 'surface'" I don't think it means putting an equal sign where the period is but I don't know why it keeps getting errors like this. If this doesn't start working soon I might just give up on making it.[/QUOTE] On line 31, I changed 'HudArmor' to 'hudArmor' and ran it. And it works, in the sense that it makes the default HUD disappear and draws huge red numbers on my screen.
[QUOTE=Jcw87;26537596]On line 31, I changed 'HudArmor' to 'hudArmor' and ran it. And it works, in the sense that it makes the default HUD disappear and draws huge red numbers on my screen.[/QUOTE] Okay it works for you but did you get this for an error: HUDDistrict9.lua:16: '=' expected near 'surface' I keep getting it no matter what I do.
Did you change the line of code he was talking about?
[QUOTE=TheFallen(TF2);26552114]Okay it works for you but did you get this for an error: HUDDistrict9.lua:16: '=' expected near 'surface' I keep getting it no matter what I do.[/QUOTE] I never got that error. Make sure you run the script clientside.
[QUOTE=Lord Ned;26553509]Did you change the line of code he was talking about?[/QUOTE] I did. [editline]7th December 2010[/editline] [QUOTE=Jcw87;26554272]I never got that error. Make sure you run the script clientside.[/QUOTE] I did I got that error in the console and in the debugger.
Would there be any way to disable a clients custom HUD from showing? afaik HUDShowDraw only disables HUD elements from vanilla gmod.
Don't use this silly debugger that's built into whatever program. Post your entire code again, and make sure you're loading the correct lua file in-game.
[lua]function HideHudBits( name ) if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" or name == "CHudSecondaryAmmo") then return false end end hook.Add( "HUDShouldDraw", "HideHudBits", HideHudBits ) surface.CreateFont( "D9 non-humans", 100, 400, false, false, "D9NonHumans" ) hook.Add ( "HUDPaint", "D9HudPaint", function() local hudPlayer = LocalPlayer() local hudHealth = hudPlayer:Health() local hudArmor = hudPlayer:Armor()E surface.SetDrawColor( 128, 128, 128, 255) surface.DrawRect( 1, 34, 25, 25 ) surface.SetTextColor( 255, 0, 0, 255 ) surface.SetTextPos( 34, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( hudHealth ) surface.SetDrawColor(128, 128, 128, 255) surface.DrawRect(1, 24, 25, 25) surface.SetTextColor(255,0, 0, 255) surface.SetTextPos(24, (ScrH()/2) + (ScrH()/4) ) surface.SetFont("D9NonHumans") surface.DrawText( hudArmor ) end)[/lua]
[QUOTE=TheFallen(TF2);26555598][code] local hudArmor = hudPlayer:Armor()[highlight]E[/highlight] [/code][/QUOTE] :doh:
Yeah you seriously need to read your code. This is twice now you've said nothing is wrong and that you did it exactly as posted, or that you checked it all for errors and twice now you've missed very obvious ones.
Okay I fixed it and its working fine again, the only problem is that the rectangle is in the wrong place but I can fix that.
Sorry, you need to Log In to post a reply to this thread.