Lua Functions in Jacob1's Mod

From The Powder Toy
Revision as of 17:12, 12 December 2012 by jacob1 (talk | contribs) (start on descriptions for functions, move to a new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

There are some general lua improvements I made in my mod:

Press tab to autocomplete any lua function name. This is helpful if you forgot the name of one but at least know how it starts.

Almost all lua functions that set a property, ex. tpt.setfpscap or tpt.set_pressure, also have a get function. Just don't pass in any arguments to the set function to get the value instead, ex. tpt.set_pause() would return whether the game i paused or not. Adding in tons of get functions would be too complicated and long to do, this way is easier. An exception to this is the functions like tpt.get_pressure where I already added in a separate function.

Lua code can also be including inside of saves to be ran on open (if the user click's yes). Click the LUA button in the FAV2 menu, and it will read the file "luacode.txt" and save it. When loading a save, the code is written to "newluacode.txt", and then a prompt comes up asking if you want to run the code. The code is executed in a lua sandbox, so it can't touch any files on your computer or send anything to the internet. At worst, it will exit the game, because os.exit() is allowed.

For the new functions, I made all of ones listed below. I plan to add some to tpt++ in different api's sometime:

tpt.sound

Play a sound just like !sound file.wav will do. It has to be a .wav

It will return an error if it can't find an audio device, you must launch tpt with the argument "sound"

tpt.sound(string filename)

tpt.load

Just like !load id, but in lua.

tpt.load(number id)

tpt.bubble

Just like !bubble x,y but in lua. Creates a SOAP bubble in a perfectly round shape

tpt.bubble(number x, number y)

tpt.reset_pressure

Resets the pressure on the entire screen, like '=' was pressed

tpt.reset_pressure()

tpt.reset_temp

Just like !reset temp, it will reset the temperature of everything to it's default value. Note: This will also reset wifi's temp

tpt.reset_temp()

tpt.get_pressure

Gets the pressure at a coordinate. The coordinates are on the CELL grid, so divide the x and y arguments by 4 before you call this, or else you might get an out of range error.

tpt.get_pressure(number x, number y)

tpt.get_aheat

Gets the ambient heat at a coordinate. This works just like the pressure and wall grids, so divide the coordinates by 4.

tpt.get_aheat(number x, number y)

tpt.get_velocity

Gets the velocity at a coordinate. This is not a particle's velocity, this is what is seen when you press 1, the velocity of the air.

For the direction argument, pass in either "x" or "y" depending on whether you want vx or vy

tpt.get_velocity(string direction, number x, number y)

tpt.get_gravity

Gets the Newtonian gravity at a coordinate. Newtonian gravity is also on a CELL grid. direction should be either "x" or "y". If you want to get the total Newtonian gravity at a point, that doesn't work for some reason, so it always returns 0. That will happen if you don't pass in a direction argument.

tpt.get_gravity(number x, number y, string direction)

tpt.maxframes

Sets the maximum number of frames ANIM can have. By default, it's 25 frames because saves get huge quickly, but you can change it with this. It must be between 1 and 256. This function will also reset all existing animations.

tpt.maxframes(number newmaxframes)

tpt.get_wall

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.create_wall

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.clear_sim

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.reset_elements

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.indestructible

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.moving_solid

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.create_parts

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.reset_elements

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.create_line

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.floodfill

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.save_stamp

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.load_stamp

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.set_selected

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.set_decocol

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)

tpt.outside_airtemp

Display an OK-Only message box with a title and message.

tpt.message_box(string title, string message)