ID:2405647
 
Code:
mob/create_character
Login()
spawn()
var/empty = "<empty-slot>"
var/list/res = src.CheckSave()
var/ans = src.LoginOptions(res)
var/compare = cmptext(ans,empty)
if(compare)
src.CreateCharacter()
else if(cmptext(ans,""))
world<<"Cancel"
else
src.LoadProc()


Problem description:
I'm trying to check if the output of src.LoginOptions() is equal to empty. The code above returns 0, as well as doing a simple
switch(ans)
if("<empty-slot>")

doesn't work. Don't know what to do, this should be an easy thing to do
NO no, I'd like to check if it's equal to empty-slot. For some reason the forums don't show the text in between < and >
So... you're making a list with this CheckSave() proc

Passing it through LoginOptions()

Checking to see if the result comes out to be "<empty-slot>"

then checking to see the result of that.

I would assume you need to see what those 2 procs are doing.

Specifically the LoginOptions() one and what its returning.


If its returning "<empty-slot>"
if(cmptext(ans,empty))

then that should return a 1, and if not, then it'll always be a 0.
Just use the == operator instead of cmptext().
Lemme show you the full process
This code is about a create/load character interface I'm trying to make.
mob/proc/CheckSave()
var/FileName = "Players/[ckey(src.key)]/"
if(fexists(FileName))
return flist(FileName)
else
return list()

Checksave is supposed to return a list of characters the user has(if he has any) or an empty list if he doesn't have any characters.
mob/proc/LoginOptions(var/list/ans)
var/empty= "<empty-slot>"
if(ans.len <6)
for(var/i=0;i<=(6-ans.len);i++)
ans.Add(empty)
ans.Add("Null")
var/text = "Click on an empty slot to create a new character \nClick on a name to Load"
cell_hoverbgcolor = "000000" //The color of the background of the item your mouse is over in the input.
cell_hovertextcolor = "FF0000" //The color of the text of the item your mouse is over in the input.
cell_normalbgcolor = "FFFFFF" //The color of the background of every item your mouse is not over.
cell_normaltextcolor = "000000" //The color of the background of every item your mouse is not over.
return skin_input(src,text,"Welcome", ans, "Welcome",5,"horizontal")

LoginOptions checks the amount of characters the user has(with the list returned by CheckSave()) and adds empty-slots to it according to the amount of characters you can have. On click. it returns what you've clicked, like this :
https://imgur.com/i4gvgF6
So, if the user clicks a "empty-slot", I check if it's equal to "empty-slot" but it's returning false for some reason.
**I've tried doing if(ans == "empty-slot") but it also doesn't work.
Put in some debugging code to show you what LoginOptions() is actually returning. That will tell you something useful about what's going on.

Something like this:
src << "Returned: [json_encode(ans)]"
Output I got from this code :
https://imgur.com/a/cz7f2pa
Use the json_encode(). It may show something that isn't showing up by just outputting the string directly.
Your output in that link is showing quotes?

Like...

world<< "ans:[json_encode(ans)]"


Shouldn't your result come out to be

ans:<empty-slot>

not...

ans:"<empty-slot>"

or does json_encode() do that?
Resolved
The LoginOptions function(especifically the skin_input()) was returning an Obj rather than a string. All I had to do was create an Obj and have it receive the return value of LoginOptions() from which I could access it's string using Obj.name. Here's the working code:
mob/create_character
Login()
spawn()
var/obj/o = new /obj
var/empty = "<empty-slot>"
var/list/res = src.CheckSave()
o = src.LoginOptions(res)
if(o.name == empty)
world<<"compare"
src.CreateCharacter()
else if(o.name == "")
world<<"Cancel"
Logout()
else
src.LoadProc(o.name)