Hello All!
This is my first time posting and I’m quite new to programming in Garry’s Mod, but have experience in C++ and VHDL. I’ve been able to program a .lua file to count the number of steps based on the PlayerButtonDown function and stored the information in a variable named count. I want to be able to display the updated value whenever it is changed in HUDPaint using a custom font which I’ve named “DisplayFont”. What I’ve found is that it only displays the initial value of count, but doesn’t bother displaying any changes to the variable count. If I locally declare it in the function, it’ll change. Would anyone happen to have any ideas of what’s gone wrong? Thank you!
//Font Creation
hook.Add( “Initialize”, “FontCreate”, function()
surface.CreateFont( "DisplayFont", {
font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 100,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
end )
//Count increases depending on the w key
hook.Add(“PlayerButtonDown”, “Count_Steps”, function( ply, key )
if((key == KEY_W)|| (key == KEY_O)) then
//net.Start("Walk_Path")
if(key == KEY_W) then
count = count+1
PrintMessage(HUD_PRINTTALK, count)
elseif(key == KEY_O) then
count = 0
else
count = count;
end
end
end)
//Display the number of steps taken
hook.Add(“HUDPaint”, “MyHudName”, function ()
draw.DrawText(count, “DisplayFont”, ScrW() / 2 - 70, ScrH() - 63, Color(255, 255, 255, 255),TEXT_ALIGN_CENTER)
end)