+twolpert Posted February 17, 2008 Share Posted February 17, 2008 Since there's no useful documentation, we're forced to find out what we can from the Lua runtime. If you'd like to take your life in your hands , you too can reverse engineer the player environment to find information about properties and methods available on the various objects. To begin, create and publish a dummy cartridge to your local machine. Something created with the wizard will do nicely. Open the emulator and load your cartridge into it. Click Play. Now switch to the Lua Debug tab. Veeerrrrry carefully, type the following in the command box. Remember that Lua is case-sensitive. Better yet, copy and paste from here. The example examines the Player object. You can change the first line to examine any object instance which is accessible. local o = Player; print(o); print(getmetatable(o)); for k,v in pairs(getmetatable(o)) do print(k,v) end; print(getmetatable(o)._self); for k,v in pairs(getmetatable(o)._self) do print(k,v) end; Click the Execute Lua Command... button. Your results will appear in the result box. Counterintuitively, they appear in reverse order with the output of your last statement at the top of the result list. The result box lacks a vertical scroll bar. To see all of your results, you may need to click in the result box. Then use standard Windows text navigation keys (such as up- and down-arrow, page-up and page-down, etc.) to navigate. The above commands should show something like this: GetVisibleObjects function: 036A5890 GetVisibleInventory function: 036A5918 PositionAccuracy Distance(1, 'm') CurrentBearing false Commands table: 0366B1F0 Name Builder Icon false GetContainer function: 0364A7E8 Cartridge a ZCartridge instance ObjIndex -21555 Gender It CommandsArray table: 0366B218 SetObjectLocation function: 0364A900 GetActiveVisibleZones function: 03685130 IsObjectVisible function: 036A58B0 RefreshLocation function: 03668400 Container false CurrentDistance false serialize function: 03660988 ProcessLocation function: 036683E0 InsideOfZones table: 03685108 Description InsideOf function: 036A5938 Inventory table: 036472D8 OnEnterZone function: 0364A850 OnExitZone function: 0364A898 Id -1 LastLocationUpdate 1203287121 Type PC OnSetInventory function: 0364A830 GetActiveVisibleTasks function: 036A5818 GetActiveTimers function: 036A58D0 CompletionCode builder ObjectLocation ZonePoint(38.636607, -90.574608, Distance(0, 'm')) Media false Visible false table: 036A4A98 __newindex function: 0368AD70 __tostring function: 0366D9A0 _self table: 036A4A98 __index function: 0368AD90 table: 03647200 a ZCharacter instance Reading from the bottom up: print(o) yields "a ZCharacter instance", which tells us the class of the the object Player. (Every instance exposes some information about itself when you simply print it. The amount and usefullness of the information varies according to the definition of the class.) print(getmetatable(o)) yields "table: 03647200". This just tells us that the Player object has a metatable which describes itself. for k,v in pairs(getmetatable(o))... yields the lines beginning with __index and ending with __newindex. This is not useful information. I only left this step in so you can see where we get the reference to _self. print(getmetatable(o)._self) yields "table: 036A4A98". Just tells us that ._self is also a table. for k,v in pairs(getmetatable(o)._self)... yields all the remaining lines, which are the visible properties and methods on the Player object. Of course, this doesn't really give us enough information to call methods. And I'm sure it exposes a number of things which we should not play with . On the other hand, several of the properties on the Player object (such as ObjectLocation and PositionAccuracy) have been discussed in other threads. So at least you have things about which you can ask specific questions. You may wish to try changing Player to Player.ObjectLocation in the first line just to see how this works. You may also want to copy/paste your results into Notepad or your favorite word processor so you can refer to them later. TODO: Find out why not all methods are exposed. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.