Author Topic: get amount  (Read 3229 times)

0 Members and 1 Guest are viewing this topic.

jojo_f
  • Newbie
  • *
  • Posts: 21
    • View Profile
get amount
« on: February 19, 2018, 04:16:29 AM »
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.

jojo_f
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: get amount
« Reply #1 on: February 19, 2018, 06:11:46 AM »
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...

llamazing

  • Full Member
  • ***
  • Posts: 221
    • View Profile
Re: get amount
« Reply #2 on: February 19, 2018, 06:45:40 AM »
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

jojo_f
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: get amount
« Reply #3 on: February 19, 2018, 07:28:57 AM »
Yes that works great thanks! Still going through the Lua API for ideas on the arrow code ..

jojo_f
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: get amount
« Reply #4 on: February 19, 2018, 10:30:29 AM »
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")