Lua Functions in Jacob1's Mod

From The Powder Toy
Jump to: navigation, search

First, there are some general lua improvements I made in my mod:

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

Lua code can also be included inside of saves to be ran on open (if the user clicks 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 or crash the game. See the readme for more info.

To detect the mod, use tpt.version.jacob1s_mod to get the current version number. Other version numbers you can use are tpt.version.jacob1s_mod_minor (minor version), tpt.version.jacob1s_mod_save (saving code version), and tpt.version.jacob1s_mod_build (build number that's used in updates)

Below is the list of new functions I added. Note that most of the new functions were removed in version 30 because they were just duplicates of things the new official APIs can do.

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.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.indestructible

Makes an element completely indestructible, like DMND. This will also prevent any state changes it has, or anything that tries to delete it like BHOL from doing that. The second argument is optional, but if that argument it 0, it will remove indestructible status from that element. And yes, it works on DMND too. The first can be either an id or name.

tpt.indestructible(number elementid)

tpt.indestructible(number elementid, bool (0 or 1) indestructible)

tpt.indestructible(string name)

tpt.indestructible(string name, bool (0 or 1) indestructible)

tpt.oldmenu

Turns the old menu (press 'o') on or off. This changes the interface slightly and probably noone uses it but this function is here so things like the tptmp button can move automatically. With no arguments it returns whether the old menu is on or off currently.

tpt.oldmenu(bool (0 or 1) setting)

number tpt.oldmenu()

gfx.tooltip

Creates a tooltip on screen. It will instantly begin fading away unless you call this every frame, or set alpha to a number higher than 255 (in that case it will count down and only start fading away at 255).

ID sets the tooltip ID you want to modify (to modify normal game tooltips). Some tooltips have special code to handle them, but ID's 0 to 4 set the bottom left tooltip, the element tooltip, the center tooltip, the quickoptions tooltip, and the intro text tooltip respectively. Leaving it blank uses ID 5.

Example to remove the intro text tooltip: gfx.toolTip("", 0, 0, 0, 4)

gfx.tooltip(string tooltip, number x, number y, [number alpha], [number ID])

sim.stickman

Modifies or fetches stickman properties. Advanced function, directly modifies the stickman struct.

sim.stickman(num, property, [nil, offset])

sim.stickman(num, property, value, [offset])

num controls the stickman to modify. 1 for STKM, 2 for STKM2, and 3-102 for FIGH.

property controls the property to get/set. Valid single options are "comm", "pcomm", "elem", "spwn", "frames", "spawnID", and "rocketBoots"
Some properties are arrays. You can use offset to control the array index. Valid array properties are "legs" (0-15) and "accs" (0-7). If fetching a value, use nil for argument 3.

argument 3 is the optional value to set. If not provided, it will return the current value instead.