Login to ZARP
Username: Password: Remember me

TOPIC: Need Help With Lua

Need Help With Lua 7 years 5 months ago #444578

So i have this Scripting Error spammed in my console and i dont know how to fix it.
I have finished a part of my Hud, which is the text inside my health bar (The red bar), but it has some scripting errors even though the text applies to my game.

Also i am a beginner so take it easy :)

Here are more details.

Ignore the text below the Health bar xD

Script Where The Errors Are Occuring:




The HUD In-Game:



Console: (This pic was taken in singleplayer meaning that when i open the console the game freezes so you cant see that the script was getting spammed)






Now Links to Gmod's Wiki:
draw.Text (wiki.garrysmod.com/page/draw/Text)
draw.Text Structure (wiki.garrysmod.com/page/Structures/TextData)
  • RFlex
  • RFlex's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP
  • whats up
  • Posts: 5684
  • Thanks received: 997
  • Karma: -60
Last Edit: 7 years 5 months ago by RFlex.
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444588

IM going off other programming languages.

It looks like an indent is needed.
  • TimeForPug
  • TimeForPug's Avatar
  • Offline
  • Adept Boarder
  • ZARP VIP Golden Blue Badge
  • Posts: 6768
  • Thanks received: 1213
  • Karma: -15
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444592

  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444593

TimeForPug wrote:
IM going off other programming languages.

It looks like an indent is needed.
Yeah, you're right. You need to ensure your methods/statements are indented when they're declared within a function. Same goes for if selectors and so on.

For example:
hook.add("HUDPaint", "DrawMyHud", function()
	local health = LocalPlayer():Health()
	-- local ammo = LocalPlayer(): needs adjusted
	local armour = LocalPlayer():Armor()
	
	draw.RoundedBox(0,8,8,300+4,30+4) -- background for health bar
	draw.SimpleText("HEALTH: " + health, "hudText",10 + 150,10 + 15,Color(255,255,255),1,1)
	draw.RoundedBox(0,10,10,health * 3,30,Color(255,120,120)) -- health bar
	

end)

When it's not indented it falls out of scope and will not execute with the function. I'm not sure if this code actually works, it was just something I blasted out quickly without thinking too hard.
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2440
  • Karma: 123
Last Edit: 7 years 5 months ago by .uzi.
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444602

.uzi wrote:
TimeForPug wrote:
IM going off other programming languages.

It looks like an indent is needed.
Yeah, you're right. You need to ensure your methods/statements are indented when they're declared within a function. Same goes for if selectors and so on.

For example:
hook.add("HUDPaint", "DrawMyHud", function()
	local health = LocalPlayer():Health()
	-- local ammo = LocalPlayer(): needs adjusted
	local armour = LocalPlayer():Armor()
	
	draw.RoundedBox(0,8,8,300+4,30+4) -- background for health bar
	draw.SimpleText("HEALTH: " + health, "hudText",10 + 150,10 + 15,Color(255,255,255),1,1)
	draw.RoundedBox(0,10,10,health * 3,30,Color(255,120,120)) -- health bar
	

end)

When it's not indented it falls out of scope and will not execute with the function. I'm not sure if this code actually works, it was just something I blasted out quickly without thinking too hard.

Indenting isn't needed its just that he used draw.Text which needs a data structure
hook.add("HUDPaint", "DrawMyHud", function()
	draw.Text( {
		text = "test",
		pos = { 50, 50 }

	} )
end)
  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
Login or register to post a reply.
The following user(s) said Thank You: .uzi

Need Help With Lua 7 years 5 months ago #444608

DEADMONSTOR wrote:
Indenting isn't needed its just that he used draw.Text which needs a data structure
hook.add("HUDPaint", "DrawMyHud", function()
	draw.Text( {
		text = "test",
		pos = { 50, 50 }

	} )
end)
There you go, you learn something new everyday!
  • .uzi
  • .uzi's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Golden Blue Badge
  • Foos yer doos?
  • Posts: 6005
  • Thanks received: 2440
  • Karma: 123
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444612

hook.add("HUDPaint", "DrawMyHud", function()
       draw.SimpleText( "lol", DermaDefault", 0, 0, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) 
end)

Should work just change cords and text and color :D
  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
Last Edit: 7 years 5 months ago by DEADMONSTOR.
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444658

Alright both work but i need the text on top of all the previous Huds, currently it shows it under the red Health bar
  • RFlex
  • RFlex's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP
  • whats up
  • Posts: 5684
  • Thanks received: 997
  • Karma: -60
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444669

AA RFLeX wrote:
Alright both work but i need the text on top of all the previous Huds, currently it shows it under the red Health bar

Put the line that makes the text below everything but above the end it should make itself on the top
  • DEADMONSTOR
  • DEADMONSTOR's Avatar
  • Offline
  • Former Owner
  • ZARP VIP
  • Posts: 9276
  • Thanks received: 3799
  • Karma: 80
...
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444670

Ah, I see the problem. You aren't speaking English :)
  • Studio Banter
  • Studio Banter's Avatar
  • Offline
  • Marvelous Boarder
  • ZARP VIP
  • ❤️
  • Posts: 14007
  • Thanks received: 5848
  • Karma: -60
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444671

www.ScriptFodder.com - All the help you could ever need.
  • RedPowder
  • RedPowder's Avatar
  • Offline
  • Former Owner
  • ZARP VIP Golden Blue Badge
  • Posts: 4489
  • Thanks received: 3318
  • Karma: 214
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444673

RedPowder wrote:
www.ScriptFodder.com - All the help you could ever need.

You mean

scriptfodder.com/users/view/76561197975880585
  • TimeForPug
  • TimeForPug's Avatar
  • Offline
  • Adept Boarder
  • ZARP VIP Golden Blue Badge
  • Posts: 6768
  • Thanks received: 1213
  • Karma: -15
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444676

DEADMONSTOR wrote:
AA RFLeX wrote:
Alright both work but i need the text on top of all the previous Huds, currently it shows it under the red Health bar

Put the line that makes the text below everything but above the end it should make itself on the top
That just removes the health bar for some reason.
  • RFlex
  • RFlex's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP
  • whats up
  • Posts: 5684
  • Thanks received: 997
  • Karma: -60
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444679

Not sure why you would use draw.Text() in the first place lol, but what the others said is correct and I'd suggest using the gmod wiki to solve issues as you learn more by spotting the issue yourself, good luck though.

If you really want to use draw.Text this is how you would do it.
draw.Text({
		text 	= Health,
		font 	= HealthText,
		pos 	= {550, 680},
		color 	= Color(255,255,255)
	})
  • Legendary Soldier
  • Legendary Soldier's Avatar
  • Offline
  • Former Community Manager
  • ZARP VIP Gold Badge
  • Still alive bois
  • Posts: 2602
  • Thanks received: 1431
  • Karma: 61
Former Community Manager - Current Bartender
Last Edit: 7 years 5 months ago by Legendary Soldier.
Login or register to post a reply.

Need Help With Lua 7 years 5 months ago #444683

Ahahaahah never mind just found out what i should have done. Thanks for the help.
Lock

I am so stupid
  • RFlex
  • RFlex's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP
  • whats up
  • Posts: 5684
  • Thanks received: 997
  • Karma: -60
Last Edit: 7 years 5 months ago by RFlex.
Login or register to post a reply.
Time to create page: 0.129 seconds

284 PLAYERS ONLINE

Connect to server View Gametracker DarkRP 1
17/127
online
Connect to server View Gametracker Deathrun
0/40
online
Connect to server View Gametracker TTT
0/47
online
Connect to server View Gametracker Bhop
0/32
online
Connect to server View Gametracker Surf
3/32
online
Connect to server View Gametracker Prop Hunt
0/42
online
Connect to server View Gametracker Sandbox
0/42
online
Connect to server Discord
264/792
online
Top