Another problem is that when I try to buy something, nothing happens. It seems that my coin variable is not properly being read. I have it defined in "lunaworld.lua" as "_G["coins"]" but in "lunadll.lua," when it is called it returns 0, whether I call it with "_G["coins"]" or "coins".
Code: Select all
--Level Header Info (or something like that)
_G["level_code"] = "mib
encrypt = loadAPI("encrypt")
shop = Data(Data.DATA_LEVEL, "Shop", true)
starCheck = false
keyPressed = false
function onLoad()
shop:set("item1", "shroom")
shop:set("item2", "leaf")
shop:set("item3", "fflower")
items = 3
if saveData:get("shopStar") == nil then
shop:set("item4", "star")
items = 4
end
i = 1
end
function onEvent(eventName)
if eventName == "shop" then
show_shopHUD = true
shopHUD_loaded = false
elseif eventName == "shop hide" then
show_shopHUD = false
shopHUD_loaded = false
elseif eventName == "star-trig" then
saveData:set("shopStar", 1)
end
end
function onLoop()
--Check if Star has been purchased
if starCheck == false then
starCheck = true
if saveData:get("shopStar") == 1 then
triggerEvent("star room open")
end
end
if shopHUD_loaded == false then
HUD_loaded = true
if show_shopHUD == true then
loadImage("../HUD/shop_hud.png", 0, 0xdc00ff)
placeSprite(1, 0, 124, 124)
elseif show_shopHUD == false then
loadImage("NONE", 0, 0xdc00ff)
end
end
if show_shopHUD == true then
local name = ""
local cost = 0
local id = 0
--Show Controls
printText("(jump) Select Item (sel) exit", 146, 370)
--Shop item list
printText(shop:get("item" .. i - 3), 156, 178)
printText(shop:get("item" .. i - 2), 156, 198)
printText(shop:get("item" .. i - 1), 156, 218)
printText(shop:get("item" .. i), 156, 238)
printText(shop:get("item" .. i + 1), 156, 258)
printText(shop:get("item" .. i + 2), 156, 278)
printText(shop:get("item" .. i + 3), 156, 298)
--Item Cost and Description
if shop:get("item" .. i) == "shroom" then
name, cost, id = "Mushroom", 10, 9
desc1 = "Allows you to"
desc2 = "take one hit"
desc3 = "without being"
desc4 = "killed."
elseif shop:get("item" .. i) == "leaf" then
name, cost, id = "Super Leaf", 15, 34
desc1 = "allows you to"
desc2 = "glide and kill"
desc3 = "enemies with a"
desc4 = "tail."
elseif shop:get("item" .. i) == "fflower" then
name, cost, id = "Fire Flower", 20, 14
desc1 = "allows you to"
desc2 = "throw"
desc3 = "fireballs at"
desc4 = "your enemies."
elseif shop:get("item" .. i) == "star" then
name, cost = "Power Star", 1000
desc1 = "you know you"
desc2 = "want it. =P"
desc3 = "includes free"
desc4 = "Tanooki Suit."
end
printText(cost .. "", 514, 144)
printText(desc1, 466, 208)
printText(desc2, 466, 228)
printText(desc3, 466, 248)
printText(desc4, 466, 268)
--Menu Navigation
if keyPressed == false then
if player.upKeyPressing == true then
if i > 1 then
i = i - 1
end
elseif player.downKeyPressing == true then
if i < items then
i = i + 1
end
elseif player.jumpKeyPressing == true then --Attempt to purchase selected item if jump is pressed.
if(coins < cost) then
--Audio.playSFX("locked.ogg")
elseif(coins >= cost) then
if shop:get("item" .. i) == "star" then
triggerEvent("star room open")
shop:set("starRoomOpen", 1)
shop:set("item4", "")
shop:save()
items, i = 3, 3
coins = coins - cost
elseif NPC1isSpawned == false then
NPC1isSpawned = true
--Audio.playSFX("cha-ching.ogg")
coins = coins - cost
NPC.spawn(id, -199696, -200160, 0)
elseif NPC2IsSpawned == false then
NPC2IsSpawned = true
--Audio.playSFX("cha-ching.ogg")
coins = coins - cost
NPC.spawn(id, -199712, -200160, 0)
else
--Audio.playSFX("locked.ogg")
end
end
elseif player.dropItemKeyPressing == true then --Hide shop screen if select is pressed.
i = 1
NPC1isSpawned, NPC2IsSpawned = false, false --TEMPORARY. FOR TEST ONLY.
triggerEvent("shop hide")
end
keyPressed = true
end
if player.upKeyPressing == false then
if player.downKeyPressing == false then
if player.jumpKeyPressing == false then
if player.dropItemKeyPressing == false then
keyPressed = false
end
end
end
end
end
end



