Ive ran into a problem where making a HUD to display the players Heath ( using it to test and learn ). And ive noticed that when i use the draw. action ( draw.RoundedBox ) it puts script errors. Ill provide the code that is in the cl_init.lua file and also the ERROR. Could anyone explain why it dont work? Or tell me if draw. no longer works? Thanks :)
[code]
//HUD Testing
function TestHUD()
local ply = LocalPlayer()
local HP = ply:Health()
draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 ))
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 220, 108, 108, 255 ) )
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 15, Color( 255, 255, 255, 40 ) )
end
hook.Add( "HUDPaint", "TestHUD", TestHUD)
[/code]
ERROR
[code]
[ERROR] gamemodes/test lua/gamemode/cl_init.lua:18: function arguments expected near 'draw'
1. unknown - gamemodes/test lua/gamemode/cl_init.lua:0
[/code]
BTW line 18 is the first line : draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 ))
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url]
Do a check to ensure the LocalPlayer IsValid; the first few times it is run, LP isn't valid.
Show is the full code, the line may be the line before the error, or after. Basically it is saying you're calling a function ( using draw: maybe? ) without using ( ), most likely.
Ok i looked at the link i think i found something to help Thanks but still want to know what i did wrong and stuff... Here is the whole file
[code]
include( 'shared.lua' )
// Clientside only stuff goes here
//HUD Testing
function TestHUD()
local ply = LocalPlayer()
local HP = ply:Health()
draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 ))
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 220, 108, 108, 255 ) )
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 15, Color( 255, 255, 255, 40 ) )
end
hook.Add( "HUDPaint", "TestHUD", TestHUD)
//DermaTest
function DermaTest()
local base = vgui.Create( "DFrame" )
local butt = vgui.Create( "DButton" )
base:SetPos( ScrW()/2 - 225, ScrH()/2 - 100)
base:SetSize( 450, 200 )
base:SetVisible( true )
base:SetTitle( "Derma Tester" )
base:SetDraggable( false )
base:ShowCloseButton( false )
base:MakePopup()
butt:SetParent( base )
butt:SetText( "Test Button" )
butt:Center()
butt:SetSize( 150, 50 )
butt:DoClick = function()
chat.AddText( Color( 0, 0, 0), "Button Worked" )
end
end
usermessage.Hook( "Open", DermaTest )
[/code]
1. Yes if you can see something wrong the Derma thing is messed up...im not worried about that tho right now. 2. I deleted something since post so its now line 10 with the error.
By the way is your _p set LocalPlayer? so ik because mine is ply (simple)
It's actually: butt:DoClick = function()
Whenever you over-ride a function, pull by reference ( . ). When you call a function, you can use . or :, but when overwriting you need to use . for the method you posted. You could do it like this:
[code]butt.DoClick = function( self, _blah )
// stuff
end
// or
function butt.DoClick( self, _blah )
// stuff
end
// or
function butt:DoClick( _blah )
// Stuff...
end[/code]
Line 29 showed up for me.
Next, look into net-messages; they send instantly instead of next-frame. Not a huge deal, but here are 2 examples. One with net, one with PlayerBndPress: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/open_vgui_based_on_keypress.lua.html[/url]
I use my own coding standards, which is why I use _p. If you're interested, here they are: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_tutorial_quizzes/_coding_standards.lua.html[/url]
[QUOTE=Acecool;45674485]It's actually: butt:DoClick = function()
Whenever you over-ride a function, pull by reference ( . ). When you call a function, you can use . or :, but when overwriting you need to use . for the method you posted. You could do it like this:
[code]butt.DoClick = function( self, _blah )
// stuff
end
// or
function butt.DoClick( self, _blah )
// stuff
end
// or
function butt:DoClick( _blah )
// Stuff...
end[/code]
Line 29 showed up for me.
Next, look into net-messages; they send instantly instead of next-frame. Not a huge deal, but here are 2 examples. One with net, one with PlayerBndPress: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/open_vgui_based_on_keypress.lua.html[/url]
I use my own coding standards, which is why I use _p. If you're interested, here they are: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_tutorial_quizzes/_coding_standards.lua.html[/url][/QUOTE]
Idk what you are helping me with here? xD Thanks for helping with the Derma error but need help with the HUD. I tested the HUD before i put in the Derma thing. But what wrong with the HUD? Sorry if you mentioned it on the reply just could you be more specific on the problem at hand :) Thanks :)
Add an if ( !IsValid( LocalPlayer( ) ) ) then return; end in your HUDPaint....
The 3 examples I posted are 3 different ways to overwrite the DoClick function that will all work.
hahaha xD xD you just confused me i dont know nothing about !IsValid yet xD but like this??? xD
[code]
//HUD Testing
function TestHUD()
local ply = LocalPlayer()
local HP = ply:Health()
draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 ))
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 220, 108, 108, 255 ) )
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 15, Color( 255, 255, 255, 40 ) )
if ( !IsValid( LocalPlayer( ) ) ) then return
end
end
hook.Add( "HUDPaint", "TestHUD", TestHUD)
[/code]
*Please dont "spoonfeed" unless i literally am that dumb with lua xD
[QUOTE=Vizik;45674686]hahaha xD xD you just confused me i dont know nothing about !IsValid yet xD but like this??? xD
[code]
//HUD Testing
function TestHUD()
local ply = LocalPlayer()
if ( !IsValid( ply ) ) then return; end
local HP = ply:Health()
draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 255 ))
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 220, 108, 108, 255 ) )
draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 15, Color( 255, 255, 255, 40 ) )
end
hook.Add( "HUDPaint", "TestHUD", TestHUD)
[/code]
*Please dont "spoonfeed" unless i literally am that dumb with lua xD[/QUOTE]
Move it up a few lines, before any functions called on it.
Lol ok i will try it thanks :) xD Ill let you know if i have any errors. :)
[editline]13th August 2014[/editline]
[QUOTE=Acecool;45674696]Move it up a few lines, before any functions called on it.[/QUOTE]
Haha NOPE thanks so much i dont have any problem. May you tell me why that fixed it so i can learn something from it?
[QUOTE=Vizik;45674724]Lol ok i will try it thanks :) xD Ill let you know if i have any errors. :)
[editline]13th August 2014[/editline]
Haha NOPE thanks so much i dont have any problem. May you tell me why that fixed it so i can learn something from it?[/QUOTE]
[QUOTE=Acecool;45674317][url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url]
Do a check to ensure the LocalPlayer IsValid; the first few times it is run, LP isn't valid.
Show is the full code, the line may be the line before the error, or after. Basically it is saying you're calling a function ( using draw: maybe? ) without using ( ), most likely.[/QUOTE]
Inside proper_hud_creation
[quote]//
// Proper HUD Creation - Josh 'Acecool' Moser
// Typically when we add a new HUD, we hook.Add( "HUDPaint", ... it without much other thought...
// This tutorial shows how to create a hud properly, with correct HUDShouldDraw logic and Player IsValid.
//
//
// Revision, added more "options" / checks for different scenarios to help simplify when what is used where and how.
//
// "Mandatory" checks are "mandatory" because we want to make sure the player is able to access their own vars, and
// the LocalPlayer must be valid to do so. HUDPaint CAN run when LocalPlayer isn't valid yet which is
// why it is important.[/quote]
**HUDPaint CAN run when LocalPlayer isn't valid yet which is why it is important.**
Glad it is solved; please mark the topic as solved in the top left :-)
No problem thanks you help me and taught me alot :D
Sorry, you need to Log In to post a reply to this thread.