ID:160174
 
I've been using a silly method of checking if a list contains anything because if(the_list) doesn't work. Is there an easy way to make sure lists contain something with a single if statement?


Silly question number two:

When using Boolean operators, see the following:

var/omgimtrue=0
if(!omgimtrue) world<<"uh wat? kthxbai." //returns message.

var/omgimtrue=1
if(!omgimtrue) world<<"o" //returns nada.

And now for the big question:

var/omgimtrue=-1
if(!omgimtrue) world<<"lol" //so I guess -1 is a true value?



I just wanted to clarify, thanks.
Speedro wrote:
I've been using a silly method of checking if a list contains anything because if(the_list) doesn't work. Is there an easy way to make sure lists contain something with a single if statement?

if(my_list && my_list.len)


That checks if the list exists and if it has a length.

Silly question number two:

When using Boolean operators, see the following:

var/omgimtrue=0
> if(!omgimtrue) world<<"uh wat? kthxbai." //returns message.
>
> var/omgimtrue=1
> if(!omgimtrue) world<<"o" //returns nada.
>
> And now for the big question:
>
> var/omgimtrue=-1
> if(!omgimtrue) world<<"lol" //so I guess -1 is a true value?

I just wanted to clarify, thanks.

-1 is a value. The ! operator will check for the absence of value. In such case, that's null, 0 and "".
//This can check if a list has elements. First it checks
//that the value passed is a list, then it checks if the
//list has a length, meaning there's something in it.
#define has_elements(l) (istype(l, /list) && length(l))

var/list
a = list("bloop", "blarg")
b = list()

if(has_elements(a))
world << "Good. :)"
if(has_elements(b))
world << "Bad. :("


As for question number two, false values are only 0, null, and an empty string. Anything else is true.
In response to Popisfizzy
Just note that some of those elements can be anything ranging from null to numbers to text.