Type == boolean

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Type == boolean

Post by tentus »

Tripped over this problem this evening and was wondering if I'm missing something obvious. I'm converting misc data to strings for output, and found this to not work at all:

Code: Select all

if type(foo) == boolean then
By contrast, this works just fine:

Code: Select all

if type(foo) == string then
Any ideas?
Kurosuke needs beta testers
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Type == boolean

Post by slime »

boolean is (probably) a nil value. string is a table. type(val) returns a string with the type name, therefore you need to compare it to another string:

Code: Select all

if type(foo) == "boolean" then print("bool") elseif type(foo) == "string" then print("str") end
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Type == boolean

Post by tentus »

Ooooh, that's... painfully obvious now that you explain it to me. Ah well, live and learn! (Hanging on the edge of tomorrow...)
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests