Author Topic: get amount  (Read 266 times)

jojo_f

  • Newbie
  • *
  • Posts: 18
    • 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
  1. function shop_heart:on_interaction()
  2.  
  3.  if        game:get_life(max)
  4.  then   game:start_dialog("already_have")
  5.            sol.audio.play_sound("bounce")
  6.  
  7.  elseif   game:get_money() < 10 then
  8.            game:start_dialog("cant_buy")
  9.            sol.audio.play_sound("bounce")
  10.  
  11.  else     game:start_dialog("empty" , function()
  12.            hero:start_treasure("heart" , 1)
  13.            game:remove_money(10)
  14.       end)
  15. end
  16. 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
  1. function shop_arrows:on_interaction()
  2.    
  3.   if  item:get_amount("arrow" , 30)
  4.     then game:start_dialog("already_have")
  5.  
  6.     elseif game:get_money() < 80 then
  7.       game:start_dialog("cant_buy")
  8.       sol.audio.play_sound("bounce")
  9.  
  10.     else  game:start_dialog("empty" , function()
  11.           hero:start_treasure("arrow" , 3)
  12.           game:remove_money(80)
  13.       end)
  14. end
  15. end

Thanks so much.

jojo_f

  • Newbie
  • *
  • Posts: 18
    • 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: 113
    • View Profile
Re: get amount
« Reply #2 on: February 19, 2018, 06:45:40 am »
Try this
Code: Lua
  1. function shop_heart:on_interaction()
  2.   if game:get_life() == game:get_max_life() then
  3.     game:start_dialog("already_have")
  4.     sol.audio.play_sound("bounce")
  5.   elseif game:get_money() < 10 then
  6.     game:start_dialog("cant_buy")
  7.     sol.audio.play_sound("bounce")
  8.   else
  9.     game:start_dialog("empty", function()
  10.       hero:start_treasure("heart", 1)
  11.       game:remove_money(10)
  12.     end)
  13.   end
  14. end

jojo_f

  • Newbie
  • *
  • Posts: 18
    • 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: 18
    • 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
  1.   if  game:get_value("amount_bow")==30
  2.     then game:start_dialog("dont_need")