The Situation
I am scripting actions of certain cards in my trading card game. Each card has there own Lua script that loads there scriptable behaviors for them (for special card effects that alter the rules of the game). Things like onTrash or onPlaced lie in the Lua script files.
The project structure is like so:
Root Folder
~ data
> cards
* behaviors
- 011.lua
- 012.lua (The files are named after the id of the cards)
- etc…
* cards.json (Contains an array of data for the cards)
~ main.lua (For now we’ll say the cards are loaded in main.lua)
Cards are loaded the cards.json file. A for loop goes through the array in the json file and applies an effect using a script that is associated with the card.
The script looks like this:
[lua]local M = {}
function M.main(card)
function card:onPlace(event)
end
function card:onTrash(event)
end
function card:onDraw(event)
end
function card:activate(event)
end
end
[/lua]
The game is supposed to require the script and apply the functions you see to the card object passed through.
The Problem
The problem is the script works in the simulator if I run it from sublime and only from any other file besides the card script. When I build the app for android, it doesn’t work either.
Here is the code:
[lua]for k,v in ipairs(cards) do
if v.type == “effect” then
local behavior = require(“data.cards.behaviors.” … string.format("%03d", v.id))
if behavior then
behavior.main(v)
end
end[/lua]
I was wondering if it had something to do with my code, the simulator, or just Corona SDK?