Page 1 of 1

Elements/prototypes should be enumerable

Posted: Wed May 28, 2014 7:53 am
by robhol
Either an iterator (not sure if this is possible?) or a method on Entity that exposes the "keys" would be a good idea in the absence of documentation. If it's a method, it'd also be nice to be able to filter the keys so that you only get the ones that are specific to that element.

Re: Elements/prototypes should be enumerable

Posted: Thu Jul 24, 2014 4:27 pm
by JLBShecky
This would be one of the most useful things out there for working with the API as it stands.

At the moment most if you try using pairs to find out about an entity or object in the game, all you get back is __self with a data type of userdata which tells you nothing about the structure of the object or any game things it may expose. It seems that train.schedule works this way at the moment, but nothing else that I have found so far acts similarly.

Re: Elements/prototypes should be enumerable

Posted: Fri Jul 25, 2014 8:36 am
by slpwnd
Not exactly the same thing, but try

Code: Select all

game.player.print(game.player.help())
The help() method should work for any rich lua object.

Re: Elements/prototypes should be enumerable

Posted: Fri Jul 25, 2014 4:16 pm
by JLBShecky
slpwnd wrote:Not exactly the same thing, but try

Code: Select all

game.player.print(game.player.help())
The help() method should work for any rich lua object.
I'll have to give that a try as soon as I get home. With it not being mentioned on the wiki, any I doubt that searching for "help" on the forums would ever give good results so I never even thought to try it.

If it tells me what I want to know I might be able to really make some headway without having to try and brute force everything by guessing possible method and property names that are not mentioned on the wiki. :D