XML to LUA

From SMTheming Wiki

Jump to: navigation, search

Contents

Introduction

Lua is actually not that different from XML; you're just replacing tags with their Lua equivalents and then wrapping the commands in cmd() .

Conversion Guides

In this section, you'll find the Lua equivalents for the XML tags.

General Things

Everything used to be wrapped in tags. Now, everything is contained within curly braces: {}. You'll see what that means in the ActorFrame section.

Commands have slightly changed as well: XML: OnCommand="commands here"

Lua (simple): OnCommand=cmd(commands here);

The command syntax itself hasn't changed, you can still (basically) use the same commands you learned with 3.9 and up. Do note the semicolon at the end, though.Those get important when making an element with more than one Command. You should also close every set of curly braces with a semicolon as well.

ActorFrame

ActorFrames occur naturally in XML, and they also appear in Lua. The key difference here is that <children> was removed. It also used to be in Lua, but now all children elements are removed from the default theme.

XML

<ActorFrame>
    <children>
        layers here
    </children>
</ActorFrame>

Lua

Def.ActorFrame{
    LoadActors here 
};

Layer

Layers are the main way to call objects with XML. They can be purposed for multiple things with the Type attribute. If attempting to convert a <Layer Type="Quad"> , see "Quad" below. For converting <Layer Type="BitmapText">, see "LoadFont" below.

XML

<Layer
  File="@THEME:GetPathG('ScreenTitleMenu',GAMESTATE:GetCurrentGame():GetName())"
  OnCommand="x,SCREEN_CENTER_X;y,SCREEN_CENTER_Y;zoomy,0;sleep,0.5;bounceend,0.5;zoomy,1;" />

Lua

LoadActor(THEME:GetPathG('ScreenTitleMenu',GAMESTATE:GetCurrentGame():GetName()))..{
  OnCommand=cmd(x,SCREEN_CENTER_X;y,SCREEN_CENTER_Y;zoomy,0;sleep,0.5;bounceend,0.5;zoomy,1);
};

Quad

XML

<Quad InitCommand="diffuse,#000000;diffusetopedge,0.5,0.5,0.5,1;" />

Lua

Def.Quad{
    InitCommand=cmd(diffuse,color("#000000");diffusetopedge,0.5,0.5,0.5,1); 
};

Complete XML to Lua Example

This example specifically deals with ScreenGameplay ready, as it is simple. The code has been slightly changed in order to remove horizontal scrollbars; everything is normally in the OnCommand.

XML

<ActorFrame>
<children>
     <Layer
         File="ready.png"
         InitCommand="x,SCREEN_CENTER_X;y,SCREEN_CENTER_Y;diffusealpha,0"
         OnCommand="linear,0.5;diffusealpha,1;sleep,0.5;linear,0.5;diffusealpha,0"/>
</children>
</ActorFrame>

Lua

local t = LoadActor( "ready" ) .. {
 InitCommand = cmd(x,SCREEN_CENTER_X;y,SCREEN_CENTER_Y;diffusealpha,0);
 OnCommand = cmd(linear,0.5;diffusealpha,1;sleep,0.5;linear,0.5;diffusealpha,0);
};
return t;

This example (and any other time where you just need to load a single file) can actually be flattened down to just:

return LoadActor( "ready" ) .. {
  InitCommand = cmd(x,SCREEN_CENTER_X;y,SCREEN_CENTER_Y;diffusealpha,0);
  OnCommand = cmd(linear,0.5;diffusealpha,1;sleep,0.5;linear,0.5;diffusealpha,0);
};
Personal tools