ID:1735323
 
(See the best response by Stephen001.)
Code:
obj
HudIntro
NameButtons
icon='Text.dmi'
Upper
layer = 100000
A
icon_state="A"
screen_loc ="2,3"

...

Click()

usr.namelist+=src.name
usr.TOSTOSC(4,10,4,4,"[usr.namelist]")

Problem description:

I created hud keyboard where you have to click on letter to create your name.

I am wondering how to detect the last letter in list and delet it because I want to create back button where you can arase your last choosen letter

Just find the end of the list with length().

var/list/letters = list("a","b","c")
mob/verb
last()
world << "The last element is [letters[length(letters)]]!"
Could you help me out a bit more I tried

                Click()
var/obj/HudIntro/NameButtons/m
if(length(usr.namelist)==m)
usr.namelist-=m

usr.TOSTOSC(4,10,4,4,"[usr.namelist]")

But nothing happend. So what am i doing wrong here?
Best response
length() returns the length of the list, AKA a number. So:
if (length(usr.namelist)==m)

Reads like:
if (12==m)

For example. By printing out the values, it should become apparent to you what is wrong about the code you've tried there:
                Click()
var/obj/HudIntro/NameButtons/m
world << "length(usr.namelist) = [length(usr.namelist)]"
world << "m = [m]"
if(length(usr.namelist)==m)
usr.namelist-=m

usr.TOSTOSC(4,10,4,4,"[usr.namelist]")
length(usr.namelist) is just a number, the index of the last element. Assuming you want to actually access the last element of the list, you need
usr.namelist[length(usr.namelist)]


EDIT: I was beaten by Stephan. Still do the exercise that he provided; it is a good example in learning debugging.
Ok i know what i did wrong and I see now stephans point but right now im really confused about everything nd dont know how can I do it to make it work
Unfortunately, we cannot help if you don't explain your problems. What are you confused about?
I tried to do it like this

                Click()
var/obj/HudIntro/NameButtons/m

if(usr.namelist[length(usr.namelist)]==m)
usr.namelist-=m

usr.close_menu(/**/)
usr.TOSTOSC(4,10,4,4,"[usr.namelist]")


and it sas it cant read from the list. I still want to access the last element of the list (not the index number) and delet it
First of all, you did not initialize m. I doubt that that m will ever be equal to the last element. Second, you should not have issues accessing the list. Did you initialize it correctly?