How To: Autocode to LunaLua

From PGE Wiki
Revision as of 03:46, 4 October 2015 by Rockythechao (talk | contribs)
Jump to navigation Jump to search

This is a guide for converting LunaDLL autocode to LunaLua code. Note that this guide is still incomplete; please refer to the LunaDLL Autocode Reference and LunaLua API for commands and functions not yet featured here.

Important Notes

  • The player2 keyword can be substituted for player to apply any filters/behavior/etc. to the second player instead of the first.
  • Some autocode commands do not have a LunaLua equivalent yet or do not require a LunaLua equivalent due to differences in how code is structured in the two languages.

Basic Filters

Autocode Lua Notes
FilterToSmall,-,-,-,-,Active time,-
player.powerup = PLAYER_SMALL;
Player loses all powerups.
FilterToBig,-,-,-,-,Active time,-
if  player.powerup ~= PLAYER_SMALL  then
    player.powerup = PLAYER_BIG;
Lowers player 1's powerup state down to "bigness" if they have anything better (fire flower, leaf...)
If you are already small or big, you will stay small or big.
FilterToFire,-,-,-,-,Active time,-
if  player.powerup > PLAYER_FIREFLOWER-1  then
    player.powerup = PLAYER_FIREFLOWER;
Lowers player 1's powerup state down to fire flower if they have anything better (leaf, hammer suit...)
If you are already small, big, or fire-flowered, you will stay that way.
You can use another powerup constant in place of PLAYER_FIREFLOWER to filter to that powerup instead.
FilterMount,-,-,-,-,Active time,-
player:mem(0x108, FIELD_WORD, 0);
Removes your mount (yoshi, clown car, boot...)
FilterReservePowerup,-,-,-,-,Active time,-
player.reservePowerup = 0;
Removes whatever is in the reserve powerup box.
Replace the 0 with another NPC ID to place that NPC in the reserve box.
FilterPlayer,-,P1,P2,-,Active time,-
-- Pre-v0.7.2
if  player:mem(0xF0, FIELD_WORD) == P1  then
    player:mem(0xF0, FIELD_WORD, P2);

-- 0.7.2 and up
if  player.character == P1  then
    player.character = P2
If the player is P1, change them to P2 instead. Replace P1 and P2 with the player constants of your choice.
To filter all other characters to P2, just use the middle line.

General Effect Commands

Autocode Lua Notes
HeartSystem,X,Y,MAX HEARTS,-,Active time,- ____ Activates a heart tracking system for players that use hearts. Allows for more than 3 hearts and displays the current heart count at X / Y on screen.
InfiniteFlying,-,-,-,-,Active time,-
player:mem(0x170,FIELD_WORD) = 52;
Keeps the player's flight timer from counting down.
ForceFacing,NPC ID,Section,-,-,Length,-
for  k,v in pairs(NPC.get(NPC ID, Section-1))  do
    v.direction = DIR_RIGHT;
    if  player.x < v.x  then
	v.direction = DIR_LEFT;
All NPCs of NPC ID in Section always face the player.

Screen commands

Autocode Lua Notes
-- v0.7.2 and up
local spdX = #
local spdY = #
local boundaryRect = Section.get(#).boundary
boundaryRect.left = boundaryRect.left + spdX
boundaryRect.right = boundaryRect.right + spdX = + spdY
boundaryRect.bottom = boundaryRect.bottom + spdY
Moves section borders.
ScreenEdgeBuffer,NPC ID,UDLR,Buffer Space,-,Length,-
local cam = Camera.get()[1]
local lMargin = cam.x - #
local rMargin = cam.x + cam.width + #
local tMargin = cam.y - #
local bMargin = cam.y + cam.height + #
for  k,v in pairs (NPC.get())  do
	if  v.x < lMargin  then
		v.x = lMargin
	if  v.x > rMargin  then
		v.x = rMargin
	if  v.y < tMargin  then
		v.y = tMargin
	if  v.y > bMargin  then
		v.y = bMargin
Keeps NPCs from leaving the screen.

Text commands


Layer commands

Set commands

Audio commands

Autocode Lua Notes
SFX,-,Sound ID,-,-,Delay,-
playSFX(int SoundID)
// or
playSFX(string Filename)
Plays one of SMBX's sound effects if you specify a number or a custom sound effect from the level folder if you specify a filename string.
Plays the music from Section.

Advanced/Misc commands