• attempt to concatenate global 'v1' (a nil value) (Garry's Mod HUD error)
    9 replies, posted
So i recently got rid of the DarkRP HUD and replaced it with a new one, but i seem to get an error i personally not able to fix. All relevant information is bellow do really appreciate help! [CODE][CODE]local function DoActualHUD() --If the variables table has not be initialized, initialize it LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {} --If the money is not set, don't do anything local v1 = LocalPlayer().DarkRPVars.money if not v1 then v1 = "" end --If the salary is not set, don't do anything local v2 = LocalPlayer().DarkRPVars.salary if not v2 then v2 = "" end end local function DrawHUD() Scrw, Scrh = ScrW(), ScrH() RelativeX, RelativeY = 0, Scrh draw.RoundedBox(5, 25, ScrH() - 175, 200, 150, Color(25,25,25,200)) surface.SetDrawColor(255,255,255) surface.SetTexture(surface.GetTextureID("gui/silkicons/user")) surface.DrawTexturedRect(25 + 10,ScrH() - 160,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/money")) surface.DrawTexturedRect(25 + 10,ScrH() - 140,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/money_add")) surface.DrawTexturedRect(25 + 10,ScrH() - 120,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/group")) surface.DrawTexturedRect(25 + 10,ScrH() - 100,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/heart")) surface.DrawTexturedRect(25 + 10,ScrH() - 80,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/shield")) surface.DrawTexturedRect(25 + 10,ScrH() - 60,16,16) draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 30,ScrH() - 165, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText("$" .. v1,"TargetID", 25 + 30,ScrH() - 145, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText("$" .. v2,"TargetID", 25 + 30,ScrH() - 125, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 30,ScrH() - 105, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer():Health() ,"TargetID", 25 + 30,ScrH() - 85, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer():Armor() ,"TargetID", 25 + 30,ScrH() - 65, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) DoActualHUD() GunLicense() Agenda() JobHelp() DrawVoiceChat() LockDown() Arrested() AdminTell() end[/CODE][/CODE] This is the full error : [ERROR] gamemodes/darkrp/gamemode/client/hud.lua:264: attempt to concatenate global 'v1' (a nil value) 1. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:264 2. unknown - gamemodes/darkrp/gamemode/client/hud.lua:372 Not very good on Fixing errors like these, would be great if someone could help me out :), HUD file will be attached - [url]http://www.mediafire.com/?grag04n5rlf1it2[/url]
v1 obviously isn't visible in the DrawHUD() function because it's defined as local in the DoActualHUD() function.
I was tryig to make it that v1 and v2 would show the salary and current money, what should I do to keep showing the money but getting it all working?
just define them in the DrawHUD() function instead of the DoActualHUD() function, then it will work. [CODE] local function DrawHUD() Scrw, Scrh = ScrW(), ScrH() RelativeX, RelativeY = 0, Scrh local v1 = LocalPlayer().DarkRPVars.money if not v1 then v1 = "" end --If the salary is not set, don't do anything local v2 = LocalPlayer().DarkRPVars.salary if not v2 then v2 = "" end draw.RoundedBox(5, 25, ScrH() - 175, 200, 150, Color(25,25,25,200)) surface.SetDrawColor(255,255,255) surface.SetTexture(surface.GetTextureID("gui/silkicons/user")) surface.DrawTexturedRect(25 + 10,ScrH() - 160,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/money")) surface.DrawTexturedRect(25 + 10,ScrH() - 140,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/money_add")) surface.DrawTexturedRect(25 + 10,ScrH() - 120,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/group")) surface.DrawTexturedRect(25 + 10,ScrH() - 100,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/heart")) surface.DrawTexturedRect(25 + 10,ScrH() - 80,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/shield")) surface.DrawTexturedRect(25 + 10,ScrH() - 60,16,16) draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 30,ScrH() - 165, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText("$" .. v1,"TargetID", 25 + 30,ScrH() - 145, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText("$" .. v2,"TargetID", 25 + 30,ScrH() - 125, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 30,ScrH() - 105, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer():Health() ,"TargetID", 25 + 30,ScrH() - 85, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer():Armor() ,"TargetID", 25 + 30,ScrH() - 65, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) DoActualHUD() GunLicense() Agenda() JobHelp() DrawVoiceChat() LockDown() Arrested() AdminTell() end[/CODE]
That worked I think because there is no more or that error now, but now there is a new one - [ERROR] gamemodes/darkrp/gamemode/client/hud.lua:286: unexpected symbol near '<' 1. unknown - gamemodes/darkrp/gamemode/client/hud.lua:0
Don't copy the </pre> </div>, it's not lua code, accidently copied it from your post
Ah yes, just ended it with "end" and it is looking much better! Just got another error though :/ [ERROR] gamemodes/darkrp/gamemode/client/hud.lua:122: attempt to index upvalue 'localplayer' (a nil value) 1. GunLicense - gamemodes/darkrp/gamemode/client/hud.lua:122 2. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:278 3. unknown - gamemodes/darkrp/gamemode/client/hud.lua:379 Sorry about this btw. Everything is good except all the text has moved up one and it needs to move down one
try using this instead of v1 and v2 [CODE](LocalPlayer().DarkRPVars.money) or 0))[/CODE] for the money and [CODE]localplayer:getDarkRPVar("salary") or 0[/CODE] for the salary, so it would be like this [CODE] draw.SimpleText("$" .. (LocalPlayer().DarkRPVars.money) or 0)),"TargetID", 25 + 30,ScrH() - 125, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)[/CODE]
Its not localplayer, it's LocalPlayer()
NVM lol, i just got rid off the shitty HUD :) - Thanks for help anyways
Sorry, you need to Log In to post a reply to this thread.