ID:2184819
 
(See the best response by Super Saiyan X.)
So I have this code (simplified here)
RemoveFromOrg()

var/list/X=new()
var/listnum=0
var/dudesname=""
switch(input("Who") as null|anything in list(
"Members X","Members Y","Leader One","Leader Two"))

if("Members X")//Is a list with the members
X=MembersX //Defines the game list where the members are
listnum=1 // Defines wich list we're goint to be using below
if("Members Y")//Is a list with the members
X=MembersY //Defines the game list where the members are
listnum=2 // Defines wich list we're goint to be using below
if("Leader One")//Is just a dude
dudesname=LeaderONE //Gets the name from the game list
LeaderONE="" //Removes the name from the game list
if("Leader Two")//Is just a dude
dudesname=LeaderTWO //Gets the name from the game list
LeaderTWO="" //Removes the name from the game list
else
return

if(X)//If the option selected is a list, not a dude.
var/Z=input("What dude in the list?","Remove Org")as null|anything in X
if(Z)//If you select a dude
switch(listnum)//Wich list we're usign?
if(1)
MembersX.Remove(Z)//Remove the name from the organization list
if(2)
MembersY.Remove(Z)//Remove the name from the organization list
dudesname=Z //Gets the name from the game list
else
return

if(dudesname)

//REST OF THE CODE


The rest of the code only runs if I select an option that is a list at the beginning. I'm guessing that if(X) is returning true even if I only defined X at the beginning. I know a workaround, but want to confirm this... Any help is appreciated. Sorry in advance for bad coding and grammar.
Best response
a list is an object. all objects evaluate to true.
If you want to check for an empty list, you should check X.len.

also this should be in dev help not byond help.
I'm not sure what you're expecting exactly, but the result you are getting is correct. The list X is initialized and thus non-null, so if(X) would return true in all cases.

P.S: This is Developer Help material.
I thought the list would only return true if something was signalized to it. Rookie mistake ^^. Thanks, and moved the topic to Developer Help.
The only values interpreted as false are 0, an empty string, and null.