get amount

Started by jojo_f, February 19, 2018, 04:16:29 AM

Previous topic - Next topic
Hi guys! I am making a shop, with NPCs for the items. The map script for the small heart works great for now.

Code ( lua) Select

function shop_heart:on_interaction()

if        game:get_life(max)
then   game:start_dialog("already_have")
           sol.audio.play_sound("bounce")

elseif   game:get_money() < 10 then
           game:start_dialog("cant_buy")
           sol.audio.play_sound("bounce")

else     game:start_dialog("empty" , function()
           hero:start_treasure("heart" , 1)
           game:remove_money(10)
      end)
end
end


but I am not sure how to properly use syntax to get the amount of the arrows item (the first "if" line).

Code ( lua) Select
function shop_arrows:on_interaction()
   
  if  item:get_amount("arrow" , 30)
    then game:start_dialog("already_have")

    elseif game:get_money() < 80 then
      game:start_dialog("cant_buy")
      sol.audio.play_sound("bounce")

    else  game:start_dialog("empty" , function()
          hero:start_treasure("arrow" , 3)
          game:remove_money(80)
      end)
end
end


Thanks so much.

Actually, I am wrong. (Or even more wrong.) With less than full hearts, the heart script still calls for dialog:"already_have" and won't sell a heart. Hmm...

Try this
Code ( lua) Select
function shop_heart:on_interaction()
  if game:get_life() == game:get_max_life() then
    game:start_dialog("already_have")
    sol.audio.play_sound("bounce")
  elseif game:get_money() < 10 then
    game:start_dialog("cant_buy")
    sol.audio.play_sound("bounce")
  else
    game:start_dialog("empty", function()
      hero:start_treasure("heart", 1)
      game:remove_money(10)
    end)
  end
end

Yes that works great thanks! Still going through the Lua API for ideas on the arrow code ..

With a little more digging I figured it out! Hooray!

Code ( lua) Select
  if  game:get_value("amount_bow")==30
    then game:start_dialog("dont_need")