ID:1126448
 
(See the best response by Jemai1.)
Code:
obj/text_obj
icon = null
New(text, s_loc, width = 380, height = 0, lyr = FLY_LAYER+3)
set_text(text)

screen_loc = s_loc

maptext_width = width
maptext_height = height

layer = lyr


Problem description:
Above code is used to create some on screen text object. Like below -
PlayerH
parent_type = /obj
var
obj/text_obj/h

New(mob/mob)
h = new/obj/text_obj(text="<text align=center><font size=1>[mob.H]/[mob.MH]</font></text>", s_loc="6:5,11:20", width=0)
h.layer = FLY_LAYER + 4
player += h

Then PlayerH is initialized in Login() proc. The problem is, when log out and re-login, it does not get deleted and it keep creating the maptext which overlapse the previous one.



Regards.

PlayerH's New proc will be called when you recreate it from your savefile. That means you're creating another /obj/text_obj on top of the saved /obj/text_obj object.

One of your options is to not save h
PlayerH
var
tmp/obj/text_obj/h // make it a tmp variable

Note: You'll have to save first then load to see the result.
It is still creating the maptext.

Regards.
Did you try deleting it at Logout()?
Are you closing the game after saving?

Jemai1 wrote:
Note: You'll have to save first then load to see the result.
^ means load your character, save it, then load it again

Another option is do an if(!h) check before creating a new one.
PlayerH
New(mob/mob)
if(!h)
h = new/obj/text_obj(text="<text align=center><font size=1>[mob.H]/[mob.MH]</font></text>", s_loc="6:5,11:20", width=0)
Blastcore:
Yes. I tried it.

Jemai1:
I am not saving it. Isn't it possible to re-login without saving?
It is still creating the overlap.

I am initializing it like this -
mob
var/tmp/PlayerH/PH
Login()
.=..()
spawn(2)
if(client)
PH = new(src)


Regards.
It is possible. That's why I asked.

If deleting it on Logout doesn't work, it is likely that you are deleting PH. Is that correct? If you delete it, all of its procs including Logout will stop.

See if the following code resolves the issue
PlayerH
Del()
del h
Not working. deleting just one variable causing everything to delete inside PH and nothing is drawn on screen.

Regards.
How are you handling loading and saving?
I am not saving the player. Just logout (close the app) and login (re-run the app). That's why I asked, isn't it possible to re-login without saving the player?
I don't want to implement save/load right now.

Regards.
Are you hosting via DreamDaemon and logging in with Dreamseeker? If so it isn't deleting itself properly as said prior....
Yes.
So, I should add a Logout button and del everything manually?

Regards.
Button? No not a button..

You need to remove it on Logout() as Jemai1 said a few posts earlier.
It was Blastcore. Though it doesn't make sense to me why his client.screen is not refreshed on re-login. This is the reason why I assumed he is saving something.

Back to my question, how are you handling Login/Logout rather?
The code are on first post. Here is the login which I posted above -
mob
var/PlayerH/PH //I remove the tmp/
Login()
.=..()
spawn(2)
if(client)
PH = new(src)
PH.show() // this is overlays -= h is PlayerH

Here is the logout -
client
New()
..()

Del()
..()

mob
Logout()
del(src)


Regards.
See if the following works
mob
Del()
if(PH)
if(PH.h) del h
del PH
..()


I am confused as to why your mana is okay. Where is the proc that populates these stuff?
Mana is not okay either. It is also creating the same bug.
On that image the value for -
health is
   75/100 and 100/100

and for mana is
   50/50 and 50/50


The health bar has nothing to do with PlayerH. It is a separate proc that takes the H and MH directly from player and update itself.

In obj/text_obj there is a proc called set_text which changes the maptext according to player's H var.
set_text(var/text)
maptext = text


Which I am calling from Attack proc.

If I delete even a single var from PH, it deletes every other objects inside PH. like mana, background etc. And on re-login I get error and it doesn't draw anything on screen.

Regards.

I mean in which proc are you adding the meter texts into your screen (or however you display it)
On Login, it is added via New() proc of PlayerH, posted on first post. set_text is called when an enemy/monster attacks player. That's it.

Edit: this is a PlayerH proc -
updateHealth(mob/m)
h.set_text("<text align=center><font size=1>[round(m.H)]/[m.MH]</font></text>")


it is called from enemy Attack proc -
if(!client)
target.UpdateHealth()
target.PH.updateHealth(target)


Regards.
Err, the part where you display it into your screen.
client.screen += atom // you won't see it unless you do something like this

Perhaps it is in PlayerH/show() ?
Page: 1 2