Graphical bar display help

Post Reply
Thylacine
Posts: 28
Joined: Sun May 10, 2009 5:04 am

Graphical bar display help

Post by Thylacine »

Code: Select all

--Creates our 'stats' bar, located at the top of the screen
function statbarStartup()
	--Health
	createLabel( "healthBack", 300, 0, 132, 20, 1)
	setBackgroundColor("healthBack", 225,0,0,100)

	createLabel("healthFront", 310, 0, 132,20,0)
	setBackgroundColor("healthFront", 0,0,0, 0)
	setFgColor("healthFront", 200,200,200)

	--Mana
	createLabel( "manaBack", 432, 0, 132, 20, 1)
	setBackgroundColor("manaBack", 0,0,225,100)

	createLabel("manaFront", 442, 0, 132,20,0)
	setBackgroundColor("manaFront", 0,0,0, 0)
	setFgColor("manaFront", 200,200,200)

	--Experience
	createLabel( "expBack", 564, 0, 132, 20, 1)
	setBackgroundColor("expBack", 0,225,0,100)

	createLabel("expFront", 574, 0, 132,20,0)
	setBackgroundColor("expFront", 0,0,0, 0)
	setFgColor("expFront", 200,200,200)

	--Balance
	createLabel( "essFront", 706, 0, 132, 20, 1)
	setFgColor("essFront", 200,200,200)
	
	--Target
	createLabel("targetFront", 838, 0, 118, 20, 1)
	setFgColor("targetFront", 200,200,200)
	if table.keyFind(globals, "target") then
		echoUserWindow("targetFront", "Target: " .. globals["target"])
	end
end

function updateStatsBar()
	clearUserWindow("healthFront")
	echoUserWindow("healthFront", "Health: " .. globals["health"] .. "%")
	if globals["health"] >= 100 then tempInt = 1 else tempInt = globals["health"]/100 end
	resizeWindow("healthBack", tempInt * 132, 20)

	clearUserWindow("manaFront")
	echoUserWindow("manaFront", "Mana: " .. globals["mana"] .. "%")
	if globals["mana"] >= 100 then tempInt = 1 else tempInt = globals["mana"]/100 end
	resizeWindow("manaBack", tempInt * 132, 20)
	--resizeWindow("manaFront", 132, 20)

	clearUserWindow("expFront")
	echoUserWindow("expFront", "XP: " .. globals["experience"] .. "%")
	if globals["experience"] >= 100 then tempInt = 1 else tempInt = globals["experience"]/100 end
	resizeWindow("expBack", tempInt * 132, 20)

	clearUserWindow("essFront")
	echoUserWindow("essFront", "Ess: " .. globals["essence"] .. "%")

        clearUserWindow("targetFront")
	if table.keyFind(globals, "target") then
		clearUserWindow("targetFront")
		echoUserWindow("targetFront", "Target: " .. globals["target"])
	else 
		echoUserWindow("targetFront", "No target!")
	end
end
That there is the code I've been using to graphically display a set of 'bars' at the top of the screen, resizing each using a quantile of the original stat.

At the moment, only the "health" portion displays correctly -- all the others are missing their text. I can get the text to display by commenting out each of the resizeWindow() lines, however that kind of defeats the purpose :P

I've checked each of the corresponding variables, and they all exist as numbers so I'm really at a loss. I guess it could be some kind of refresh issue?

Thanks, though.
Last edited by Thylacine on Tue Jun 23, 2009 10:17 am, edited 1 time in total.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Graphical bar display help

Post by Heiko »

Set the text as final layer on top of the health bar and use a fully transparent background.

Thylacine
Posts: 28
Joined: Sun May 10, 2009 5:04 am

Re: Graphical bar display help

Post by Thylacine »

Typically, it was that simple.. Just had to swap resizing/echo'ing text, and it all works now...

Thanks!

Funkymatic
Posts: 8
Joined: Mon Dec 21, 2009 11:14 pm

Re: Graphical bar display help

Post by Funkymatic »

How would one create this from scratch?

Is it as simple as copying the above script into a new 'script' within mudlet?

I have zero lua knowledge at all. I'm super keen to learn it as i'd like to get away from zmud/cmud, after just buying cmud and realising how unfinished it is as a product.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Graphical bar display help

Post by Vadi »

Pretty much. Copy to new script and use the statbarStartup() function somewhere to make it appear. updateStatsBar() in your prompt trigger to make it update to the values (you'll see that it uses "health" as your current health var, "mana" as your mana var and so on).

Post Reply