ID:170296
 
I've been experimenting with text mode lately to see what can be done with it as some of you may know and now I'm stuck again. How would you show variables on a hud in text mode?

Here is what i tried..

obj/HUD/HP
text = "<font bgcolor=#FF0033><font color=#698B69>[src.hp]</font>"
screen_loc="2,1"


Text Test.dm:219:error:src.hp:undefined var
Text Test.dm:219:error::expected a constant expression
You can only set variables to... er, variables at run-time.
In response to YMIHere
<_< Heh, bl33p, just bored, hehe. G'night, sleepy time for me.

- Super Squirrel

----------------------------------------------
Ask what one cannot eat apple pie, yet not the pastry is undone to you.
In response to YMIHere
YMIHere wrote:
You can only set variables to... er, variables at run-time.

How would i accomplish this?

~>Jiskuha
In response to Jiskuha
I notice you're using hp so I'm going to take a page from Lummox's book and use a universal TakeDamage() proc that can update the hud too. First we'll need the hud object, and a reference to it from the mob.

obj/HUD/hp_thing
screen_loc="1,1"

mob
var/obj/HUD/hp_thing/hpHUD

// We'll need these later.
var/hp=10
var/max_hp=10


The next thing we have to do is create the HUD object for a mob when it logs in.

mob
Login()
..()
hpHUD=new()


Now we've got it all setup to use. I'm going to use it in the TakeDamage() proc, so instead of subtracting from a mob's hp variable directly, you should use it.

mob
proc/TakeDamage(n)
hp=max(0, min( max_hp, hp-n )) // Restrict hp to somewhere between 0 and max_hp.
hpHUD.text="[hp]"

verb/Attack(mob/M as mob in oview(1))
M.TakeDamage(rand(1,5))
In response to YMIHere
Okay ive done all of that however nothing is displayed on 1,1 of the client's screen..

~>Jiskuha
In response to Jiskuha
Whoops! I forgot to add it to the screen. Just add it in Login() right after you create it and it should work fine. =)
In response to YMIHere
All i get on the screen is the letter H..

~>Jiskuha
In response to Jiskuha
That's the default value of the object's text variable (the first letter of it's name). If you want to change that, change the object's text variable after you create it (in mob/Login()), or you can just wait until you're attacked. =P Keep in mind, multiple letters in the text variable will be scrolled through.
In response to YMIHere
Heres what i put in mob/login()

mob
Login()
..()
src.client.screen += new/obj/HUD/hp_thing
hpHUD=new()
src.TakeDamage(0)

//Dont Mind this..
obj/HUD/hp_thing
screen_loc="3,1"

mob
proc
TakeDamage(n)
hp=max(0, min( max_hp, hp-n ))
hpHUD.text="<font bgcolor=#8B8989><font color=#698B69>[hp]</font>"


Did i do something wrong that it wont change the h to a number?

~>Jiskuha
In response to Jiskuha
Yeah, I should have specified. You're creating a HUD object and adding it to the screen, then you're creating a new HUD object to be reference by the player's hpHUD variable. That variable has to reference the object that's in the player's screen, so you create hpHUD, then add hpHUD to the screen.

  hpHUD=new()
client.screen += hpHUD


Now you can play with the object that is in the player's screen through that variable. =)
In response to YMIHere
It works,Thanks a lot mate! Also since its in text mode and its more than one number/letter it cycles through all of the numbers so it will display 1 then 0 then 0 again and repeat. Is there anyway to get it to display the full 100?

~>Jiskuha
In response to Jiskuha
You'd have to use separate object in different locations. You might want to think about just displaying the percentage of hit points if the players' hp is going to go really high.
In response to YMIHere
YMIHere wrote:
You'd have to use separate object in different locations.

Well how could i split up the 100 and put it in different locations. This sounds a little complicated..

~>Jiskuha
In response to Jiskuha
[Snippet Removed, Way too buggy!]

~>Jiskuha
In response to Jiskuha
Hmmm, remember how you did G-text?
:)
Use that text seperating proc, and make it like adding a name, except change the loc and not the pixel x/y.
In response to Hell Ramen
DeathAwaitsU has been helping me and here is what i have achieved so far..

mob/var/hp = 50

mob/Login()
src.client.screen += new/obj/HUD/HPTenth
src.client.screen += new/obj/HUD/HPOnes
src.hp-=10

src.Update()

mob
proc/Update()
var/texthp = num2text(hp)
for(var/obj/HUD/HPTenth/O in client.screen)
O.text="<font bgcolor=#8B8989><font color=#698B69>[copytext(texthp,1,1)]</font>"
for(var/obj/HUD/HPOnes/O in client.screen)
O.text="<font bgcolor=#8B8989><font color=#698B69>[copytext(texthp,2,2)]</font>"


However the 2 spaces where the 4 and the 0 should be it is a blank. Any help?

~>Jiskuha
In response to Jiskuha
Yeah um my mistake, it should be:

mob/var/hp = 50

mob/Login()
src.client.screen += new/obj/HUD/HPTenth
src.client.screen += new/obj/HUD/HPOnes
src.hp-=10

src.Update()

mob
proc/Update()
var/texthp = num2text(hp)
for(var/obj/HUD/HPTenth/O in client.screen)
O.text="<font bgcolor=#8B8989><font color=#698B69>[copytext(texthp,1,2)]</font>" //copies the first character
for(var/obj/HUD/HPOnes/O in client.screen)
O.text="<font bgcolor=#8B8989><font color=#698B69>[copytext(texthp,2,3)]</font>" //copies the second character
In response to DeathAwaitsU
Eh.. I have one last problem. If i only have 1 digit remaining the part that would hold the second digit is gone and shows a clear space through the hud. How can i fix this? I Tried using length.
Snippet:
        for(var/obj/HUDTOP/HP7/O in client.screen)
O.text="<font bgcolor=#A52A2A><font color=#698B69>[copytext(textlvl,2,3)]</font>"
length(textlvl)

Compile Error: hud.dm:181:length :warning: statement has no effect

~>Jiskuha
In response to Jiskuha
length() just returns a num.
Page: 1 2