Need Help to Get Shop to Work

Description: Archive discussion
============================
Original description:
Official subforum for LunaLua - an extension framework for SMBX Engine Version 1.3 (which a core of SMBX 2.0). Share your creations that require the use of LunaLUA. You may also share info/tutorials on how to use LunaLUA.

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #1by Sambo » 21 Jul 2015, 2:28

I have a Pokemon-like shop, but the player can still move and talk to NPCs while it is displayed. Disabling controls through events doesn't work, because the player can't move in the menu or in the level while this is in effect. Is there a way to disable a player's movement without disabling his controls completely?

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". :fool:

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
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #2by Kevsoft » 21 Jul 2015, 8:17

Maybe try to acces the coin variable with _G too. About the control overwrite: Check out the new input update event, in this function you can block specific controls.
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #3by Sambo » 22 Jul 2015, 2:55

Kevsoft wrote:Maybe try to acces the coin variable with _G too. About the control overwrite: Check out the new input update event, in this function you can block specific controls.
Blocking specific controls isn't enough because you could still jump and, this is the biggest problem, you could still talk to NPCs, so if you were close enough to the NPC you talked to to open the menu, you'd talk to him again when you tried to move up.

How would one block controls with onInputUpdate? I would look it up but that page isn't in the wiki yet.

What about the problem with the coins variable? I just performed a simple test and confirmed that variables from one file can be accessed in the other, in either direction. And It's weird. The coin variable is never defined in my "lunadll.lua" but it returns 0 instead of saying "Attempt to concatenate a nil value" when it is compared to another value or printed on the screen. It doesn't make sense. :wacko:
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #4by Kevsoft » 26 Jul 2015, 10:49

I mean if it still doesn't work you may want to try to make an API as a "bridge".
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬


Return to “LunaLua - Extension Framework”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest