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?
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.
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...
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
[Please log in to post a comment]