ID:2950450
 
(See the best response by Phat T.)
Code:
mob
icon = 'player.dmi'
var
hunger = 100
maxHunger = 100
bladder = 100
maxBladder = 100
clean = 100
maxClean = 100
fun = 100
maxFun = 100
social = 100
maxSocial = 100
energy = 0
maxEnergy = 100
Creds = 0

obj/hud_hunger
obj/hud_bladder
obj/hud_clean
obj/hud_fun
obj/hud_social
obj/hud_energy
overlays = list()

proc
decrementNeeds()
while(1)
hunger = max(0, hunger - 1)
bladder = max(0, bladder - 1)
clean = max(0, clean - 1)
fun = max(0, fun - 1)
social = max(0, social - 1)
energy = max(0, energy - 1)
updateHUD()
sleep(100)

updateHUD()
updateBar(hud_hunger,"hunger",hunger, maxHunger)
updateBar(hud_bladder,"bladder",bladder, maxBladder)
updateBar(hud_clean,"clean",clean, maxClean)
updateBar(hud_fun,"fun",fun, maxFun)
updateBar(hud_social,"social",social, maxSocial)
updateBar(hud_energy,"energy",energy, maxEnergy)

proc
updateBar(obj/hud_obj,need, current, max)
var percent = (current / max) * 100
if (percent > 75)
hud_obj.icon_state = "[need]_full"
if (percent > 50)
hud_obj.icon_state = "[need]_half"
if (percent > 25)
hud_obj.icon_state = "[need]_empty"

New()
..()
createHUD()
spawn() decrementNeeds()

proc
createHUD(client/c)
hud_hunger = new /obj/HUD/hunger_bar
hud_bladder = new /obj/HUD/bladder_bar
hud_clean = new /obj/HUD/clean_bar
hud_fun = new /obj/HUD/fun_bar
hud_social = new /obj/HUD/social_bar
hud_energy = new /obj/HUD/energy_bar

hud_hunger.screen_loc = "1,1"
hud_bladder.screen_loc = "1,2"
hud_clean.screen_loc = "1,3"
hud_fun.screen_loc = "1,4"
hud_social.screen_loc = "1,5"
hud_energy.screen_loc = "1,6"

hud_hunger.layer = MOB_LAYER + 1
hud_bladder.layer = MOB_LAYER + 1
hud_clean.layer = MOB_LAYER + 1
hud_fun.layer = MOB_LAYER + 1
hud_social.layer = MOB_LAYER + 1
hud_energy.layer = MOB_LAYER + 1

client.screen += hud_hunger
client.screen += hud_bladder
client.screen += hud_clean
client.screen += hud_fun
client.screen += hud_social
client.screen += hud_energy
updateHUD()



mob
verb
checkEnergy()
src << "Energy: [energy]/[maxEnergy]"
proc
addEnergy(amount)
energy += amount
if (energy > maxEnergy)
energy = maxEnergy
src << "Energy increased to [energy]/[maxEnergy]"


Problem description: Hello, I am trying to make a hud that shows bubbles that are various colors for each stat like hunger etc like in the Sims. I made the icons all in hud.dmi and each stat has 3 states. (like hunger_full,hunger_half and hunger_empty for example) But even though I get no errors the hud does not appear. I have not used Byond in a while and have been reading randomly on the forum and the documentation to brush up so I am likely just missing something or maybe my approch is wrong. I used to just use stat panel but I have always wanted to do away with that and use huds instead and I am hoping this would be a good learning project for me so I understand how they work better so any advice would be a big help. Thank you!

No clue. But this is a great opportunity to practice your debugging.

If the whole of the function is not working, it is your job to identify just where it is failing. First thing I'd do is comment out the updateHUD() call in your "CreateHUD()" function. From there, you can see if the problem persists. If not, then we know updateHUD() is the problem.

EDIT:

Also, lets make sure that the HUD objs all have a default icon_state.
Best response
mob
icon = 'player.dmi'
var
hunger = 100
maxHunger = 100
bladder = 100
maxBladder = 100
clean = 100
maxClean = 100
fun = 100
maxFun = 100
social = 100
maxSocial = 100
energy = 0
maxEnergy = 100
Creds = 0

obj/hud_hunger
obj/hud_bladder
obj/hud_clean
obj/hud_fun
obj/hud_social
obj/hud_energy

overlays = list()

proc
decrementNeeds()
while(1)
hunger = max(0, hunger - 1)
bladder = max(0, bladder - 1)
clean = max(0, clean - 1)
fun = max(0, fun - 1)
social = max(0, social - 1)
energy = max(0, energy - 1)
updateHUD()
sleep(100)

updateHUD()
updateBar(hud_hunger, "hunger", hunger, maxHunger)
updateBar(hud_bladder, "bladder", bladder, maxBladder)
updateBar(hud_clean, "clean", clean, maxClean)
updateBar(hud_fun, "fun", fun, maxFun)
updateBar(hud_social, "social", social, maxSocial)
updateBar(hud_energy, "energy", energy, maxEnergy)

proc
updateBar(obj/hud_obj, need, current, max)
var percent = (current / max) * 100
if (percent > 75)
hud_obj.icon_state = "[need]_full"
else if (percent > 50)
hud_obj.icon_state = "[need]_half"
else
hud_obj.icon_state = "[need]_empty"

New()
..()
createHUD(client) // Pass client to createHUD
spawn() decrementNeeds()

proc
createHUD(client/c)
// Initialize each HUD component
hud_hunger = new /obj/HUD/hunger_bar
hud_bladder = new /obj/HUD/bladder_bar
hud_clean = new /obj/HUD/clean_bar
hud_fun = new /obj/HUD/fun_bar
hud_social = new /obj/HUD/social_bar
hud_energy = new /obj/HUD/energy_bar

// Set screen location for each HUD component
hud_hunger.screen_loc = "1,1"
hud_bladder.screen_loc = "1,2"
hud_clean.screen_loc = "1,3"
hud_fun.screen_loc = "1,4"
hud_social.screen_loc = "1,5"
hud_energy.screen_loc = "1,6"

// Ensure HUD displays on top by setting a high layer
var/hud_layer = MOB_LAYER + 5
hud_hunger.layer = hud_layer
hud_bladder.layer = hud_layer
hud_clean.layer = hud_layer
hud_fun.layer = hud_layer
hud_social.layer = hud_layer
hud_energy.layer = hud_layer

// Add each HUD object to the client's screen
c.screen += hud_hunger
c.screen += hud_bladder
c.screen += hud_clean
c.screen += hud_fun
c.screen += hud_social
c.screen += hud_energy
updateHUD()

mob
verb
checkEnergy()
src << "Energy: [energy]/[maxEnergy]"

proc
addEnergy(amount)
energy = min(energy + amount, maxEnergy)
src << "Energy increased to [energy]/[maxEnergy]"
updateHUD()
In response to Phat T
What did you change?

EDIT:

Looks like you just changed the layers. But this shouldn't matter, the objects should appear as normal since it is on the screen.
- He was passing client/c to createHUD(), but not using it in New() properly.

- Also, initialized HUD correctly within the player's client screen, as client.screen directly references the HUD of the current client

- The logic in updateBar() was using consecutive if statements that could be interfering with the correct icon state display.

- Ensure the HUD layers are above the player's normal layer by setting each hud_obj.layer explicitly.
In response to Phat T
Thank you for checking over this! I will try it when I get home and see if it works. Also thank you for explaining what I did wrong and that makes a lot of sense. I was experimenting a bunch to try to fix it and used a few different approaches but ended up making it more convoluted lol.