Log In  

How i can get this code to work?

list = {}
--adds a person to the list.
function addp(name) 
    local p = {}
    p.life = 100
    p.x = 64
    p.y = 64
    p.n = name
    add(list,p)
end

function _init()
    addp("test")
    addp("touh")
    addp("chori")
    addp("kek")
end

function _draw()
    foreach(list, print)  --prints "table"
    for o in all(list) do
        if(o == table)then
            print("is a table")
        else
            print("no table")
        end
    end
end

i can't recognize a table with this code.
Any ideas?

P#17968 2015-12-21 12:34 ( Edited 2016-01-04 06:32)

3

To check if something is a table, first count the number of legs it has. A table needs to have three or four legs, at the minimum, in order to hold itself upright. If it only has one or two legs, it might be a lamp or a cardboard cut-out picturing a table, and not, in fact, a table itself.

Next, check how tall it is. A table is usually about as high as your hips when you're standing up, so that when you sit at it the contents on TOP of the table can be easily accessed with your arms, which should end up above the table. If it's taller than that, it might be a stool, or a bar, or even a counter, and not necessarily a table.

Then, check if it has a flat, hard surface on top. Tables are generally flat, although sometimes they may have an unusual bump or decoration towards the middle (such as a glass segment or engraved embellishments), but generally not in such a way that it inconveniences your use of it as a table. If it has a soft surface, it might in fact be a sofa or couch of some kind, please be aware that this is not a table.

Finally, check how large it is. A table needs to be at least large enough to carry two or three items. Try laying out a proper dinner set - a plate, a fork, a knife, a bowl, a napkin. If you can't fit all that on top of it at once, it's probably not a table.

In Pico-8's Lua, "table" is not defined, nor is "type" or anything else you would normally be able to use to determine whether or not any given object is, in fact, a table. Unfortunately, the only thing you can do is keep track of where you put your tables, so that they don't get all lost or mixed up with the rest of the non-table items in your house.

P#17979 2015-12-21 17:58 ( Edited 2015-12-21 23:00)
1

I totally agree with JTE's way of telling if something is a table or not.
In addition to it though, I recommend looking in your kitchen or living-room for an object fitting the description. Chances are you will find one there. So then you'll have an example for your object-identifying to come.

BEWARE though! Coffee tables are lower than regular table but are still fully considered as tables! This particular type of table is very commonly found in living-rooms. Office tables and kitchen tables, respectively found in offices and kitchens, are also fully considered as tables without necessarily fulfilling the regular table description.

For reference, I recommend you take a look at this well documented webpage: https://www.google.fr/search?q=table&tbm=isch

In Pico-8, although there isn't any implemented to tell tables apart from other variables, I recommend simply setting a variable isTable to 1 (or whatever) in every new table you create and then when you wanna check if something is a table do "if pieceOfFurniture.isTable then".
Or you know, just keep track of your tables...

P#18001 2015-12-22 18:34 ( Edited 2015-12-22 23:34)

That's odd because when you run

table = {}
print(table)

it display > table

so the print function can tell if an object is a table or not
why not add a simple function to do the same :/

P#18096 2015-12-30 12:57 ( Edited 2015-12-30 17:57)
1

type() will be available in 0.1.4 :)

P#18097 2015-12-30 14:25 ( Edited 2015-12-30 19:25)

More than just a a function to tell the type of a lua variable,
Could we have classes too ?
like in this web page ?
http://lua-users.org/wiki/SimpleLuaClasses

P#18102 2015-12-30 20:35 ( Edited 2015-12-31 01:35)

Thanks.
i need a "type()" function because i want to make something like an in-game debug menu.
This is what i have done:

Debug Jelpi:

P#18121 2016-01-02 16:31 ( Edited 2016-01-02 21:31)

0.1.4 is out, so type() is now available!

P#18140 2016-01-04 01:32 ( Edited 2016-01-04 06:32)

[Please log in to post a comment]