ID:139684
 
Code:
var/icon/ColorNPC='Alphabet.dmi'
obj/Supplemental/NameDisplay
icon='Alphabet.dmi'


atom/proc/Name(var/Name2Add)
var/spot=0
var/letter=" "
if(!Name2Add) Name2Add=src.name
for(var/O in src.overlays)
if(O) if(O:name=="NameDisplay") src.overlays-=O
else src.overlays-=O
while(letter!="")
spot+=1
letter=copytext(Name2Add,spot,spot+1)
if(letter=="") return
var/px=(spot*6)-(length(Name2Add)*6)/2
var/obj/Supplemental/NameDisplay/NL=new
NL.pixel_x=px
NL.icon_state="[letter]"
NL.pixel_y=-10
NL.layer=99999999999999999
usr.overlays+=NL


Problem description:



Problem i got a problem with this code I want it to show name without any spaces but when my game starts some of the letters are shown with space. can some one help me?
Hassanjalil wrote:
Problem description:



Problem i got a problem with this code I want it to show name without any spaces but when my game starts some of the letters are shown with space. can some one help me?

I'd recommend using Lummox JR's DMIFontsPlus library.

It can do variable width fonts (so that i takes up less space than w) and even has an easy-to-use proc to generate name graphics and attach them to objects.
In response to Skyspark
i used it but i am making change name as well and it dont work on that
In response to Hassanjalil
Hassanjalil wrote:
i used it but i am making change name as well and it dont work on that

All you have to do is remove the name overlay and then add a new one whenever the name changes.

Lummox JR
In response to Lummox JR
Give me an idea
In response to Hassanjalil
Hassanjalil wrote:
Give me an idea

I want to help you, but you have to meet me halfway. If you're having trouble with something, the way to get help is to show what you've tried so far. Post code snippets; describe in detail what you've done and what happened as a result. If you just tell me that it still doesn't work, that doesn't tell me anything about what you've been doing or what might be going wrong.

The only issue you've mentioned since the original suggestion to use DmiFontsPlus is that giving players the ability to change their name presented a problem. I offered a workaround. You haven't mentioned yet whether you actually did use the library or if you just decided it wouldn't work due to the aforementioned minor issue, and now you haven't said what the current problem is. I have too little information to go on to help you.

Lummox JR
In response to Lummox JR
OK this is the code i used for change name
mob/verb/Change_Name(T as text)
usr.name=T
for(var/obj/N in usr.overlays)
usr.overlays-=N
sleep(1)
CreateName()

it dont remove overlays just make new one
In response to Hassanjalil
Hassanjalil wrote:
OK this is the code i used for change name
> mob/verb/Change_Name(T as text)
> usr.name=T
> for(var/obj/N in usr.overlays)
> usr.overlays-=N
> sleep(1)
> CreateName()
>

it dont remove overlays just make new one

This is because there are no actual objs in the overlays list. Per the reference:
The individual items in the list may not be directly accessed, since they are stored in a special internal format. However, the list operators +=, -=, and the procedures Add, Remove, and Cut work normally.
In short, when you loop through the list the items in it are those special internal structures, not the objs you originally added.

Whenever something is added to the overlays list, a snapshot of it is taken, called an "appearance", and the appearance is what's actually added to the list. If you subtract an object from the list, it again takes a snapshot and tries to find a matching appearance to remove.

The reason your code isn't working is that var/obj/N is only looking for objs in the list, and it isn't finding any. If N is declared as var/N instead, all the overlays will be removed. Another way to remove all the overlays is to set overlays=null or call overlays.Cut().

Lummox JR
In response to Lummox JR
ok that make it work but what if i want more then one obj in overlays for exemple if i am making icon 64x64 i need to make head of the icon using overlays
In response to Hassanjalil
Hassanjalil wrote:
ok that make it work but what if i want more then one obj in overlays for exemple if i am making icon 64x64 i need to make head of the icon using overlays

You have a few options for this.

One option is not to use world.map_format=TILED_ICON_MAP at all, and instead use TOPDOWN_MAP, so you can mix and match icon sizes. Then you don't need an overlay for the head.

Another option is to keep track of the head overlay, the name overlays, or both. For example, if you wanted to keep a copy of the head overlay just after you've added it:

mob/var/tmp/head_overlay

mob/proc/BuildOverlay(head)
overlays += head
head_overlay = overlays[overlays.len]


What this code does is that after you've added the head overlay, which makes a copy of the head object and adds only its appearance to overlays, then it's taking the actual item from the overlays list and keeping track of that. When you want to remove everything but the head overlay, you can do this:

for(var/O in overlays)
if(O != head_overlay) overlays -= O


Because head_overlay is an appearance, not an obj, if the matching appearance is found in the list it should skip over it just like you wanted.

You can also keep track of the name overlays in the same way:

overlays -= name_overlays
var/oldlen = overlays.len
MakeNameOverlay()
name_overlays = overlays.Copy(oldlen)


In this case name_overlays is actually a list. This is probably the simpler option.

Lummox JR
In response to Lummox JR
Lummox i got that fixed but how do i add on hud like screenloc?
In response to Hassanjalil
Maybe you should try searching some terms, such as:

screen
loc
screenloc

in the forum search, and reference. Also, ADDING to the screen:

+ operator
+= operator
Add

would be some that you would probably check out, although you'll most likely be using += .