Storyboard - Game Inventory

Hi All

I am new to Corona, and really liking it.

I’m creating a Storyboard template for our (family project) escape game. (You are trapped in a room, etc., etc.) I’ve gotten most of the basics built out and working. However, I am unable to find good documentation/samples for an custom Inventory Bar in Storyboard. I didn’t see it in my copy of Corona SDK Mobile Game Development either. I tried searching the web and the corona forums, but some of the forum links are expired (searched: game inventory).

I know this is not neccessarily a tabbar, so I was thinking maybe a widget or a function. It would be 4 Inventory slots, potentially holding:

redball.png
blueball.png
yellowball.png
key.png

Any links or small code snippets would be greatly appreciated. I just want a nudge in the right direction, or any workable direction.

Thanks! [import]uid: 133581 topic_id: 31877 reply_id: 331877[/import]

Hi Monarcb,

I’m fairly new to CoronaSDK / Lua scripting as well, but here’s something I quickly made for you: https://www.dropbox.com/s/dev3iu0w74sqopc/InventoryBar.zip

It uses the physics engine for certain things, and it doesn’t use Storyboard as you requested (I haven’t used Storyboard before), but hopefully it gives you some ideas as to how you might create an inventory bar.

If you’d like me to remove the need for physics I can try and do that, or if you’d like some more comments in the code to help you understand the functionality better I can do that as well.

Simon [import]uid: 12217 topic_id: 31877 reply_id: 127312[/import]

This is perfect Simon, thank you for taking the time to create it. I can defintely use this. [import]uid: 133581 topic_id: 31877 reply_id: 127327[/import]

No problem, Monarcb. I’m glad I was able to help!

I actually did a bit more work on this, hopefully its an improvement: https://www.dropbox.com/s/psx54sx9u3wdlsm/InventoryBarV2.zip [import]uid: 12217 topic_id: 31877 reply_id: 127357[/import]

SImon this is great! You are a way better programmer than I am. I was able to encorporate a good bit of it and got the inventory bar working in my escape game template. My first objective is to get the template working, no matter what(Ugly code and all). Then go back and optimize the code and graphics. Thank you for you help! [import]uid: 133581 topic_id: 31877 reply_id: 127405[/import]

You’re welcome, Monarcb. Good luck with your project! [import]uid: 12217 topic_id: 31877 reply_id: 127417[/import]

Hi Monarcb,

I’m fairly new to CoronaSDK / Lua scripting as well, but here’s something I quickly made for you: https://www.dropbox.com/s/dev3iu0w74sqopc/InventoryBar.zip

It uses the physics engine for certain things, and it doesn’t use Storyboard as you requested (I haven’t used Storyboard before), but hopefully it gives you some ideas as to how you might create an inventory bar.

If you’d like me to remove the need for physics I can try and do that, or if you’d like some more comments in the code to help you understand the functionality better I can do that as well.

Simon [import]uid: 12217 topic_id: 31877 reply_id: 127312[/import]

This is perfect Simon, thank you for taking the time to create it. I can defintely use this. [import]uid: 133581 topic_id: 31877 reply_id: 127327[/import]

No problem, Monarcb. I’m glad I was able to help!

I actually did a bit more work on this, hopefully its an improvement: https://www.dropbox.com/s/psx54sx9u3wdlsm/InventoryBarV2.zip [import]uid: 12217 topic_id: 31877 reply_id: 127357[/import]

SImon this is great! You are a way better programmer than I am. I was able to encorporate a good bit of it and got the inventory bar working in my escape game template. My first objective is to get the template working, no matter what(Ugly code and all). Then go back and optimize the code and graphics. Thank you for you help! [import]uid: 133581 topic_id: 31877 reply_id: 127405[/import]

You’re welcome, Monarcb. Good luck with your project! [import]uid: 12217 topic_id: 31877 reply_id: 127417[/import]

Hi,

I had a small question, further expanding on inventory objects. How would I reference the active inventory object for a specific collision detection? I want a red button to trigger collision event on one scene and yellow button on another. I tried setting a InvItem2.MyName = “redbtn”, it works fine for the first scene. However, when I create and check for InvItem1.MyName = “yellbtn” (with similar code on another scene) it doesn’t work for the newly created object InvItem1. Is it incorrect to reference the actual variable and assigning it MyName=“whateverbtn”, or if there a kind of self target statment I should be use for inventory item while it’s being actively dragged?

Sample code I am using:
function mybtn:collision(event)
if event.phase == “began” and event.other.MyName == “redbtn” then
InvItem2:removeSelf()
InvItem2 = nil
InvItem1 = createItem(“assets/interact/buttonyellow.png”, 64, 64)
InvItem1.x = 255: InvItem1.y = 710
InvItem1.MyName = “yellbtn”
print (InvItem1.MyName)
end
end

Thanks for your time. [import]uid: 133581 topic_id: 31877 reply_id: 128020[/import]

I figured this one out! I had to add a timer delay to it. It tried to access physics during the collision and it was giving me an error, but continuing and running the code. However, the variables I set up (immediately afterwords) were not assigning/registering correctly. [import]uid: 133581 topic_id: 31877 reply_id: 128045[/import]

Hi,

I had a small question, further expanding on inventory objects. How would I reference the active inventory object for a specific collision detection? I want a red button to trigger collision event on one scene and yellow button on another. I tried setting a InvItem2.MyName = “redbtn”, it works fine for the first scene. However, when I create and check for InvItem1.MyName = “yellbtn” (with similar code on another scene) it doesn’t work for the newly created object InvItem1. Is it incorrect to reference the actual variable and assigning it MyName=“whateverbtn”, or if there a kind of self target statment I should be use for inventory item while it’s being actively dragged?

Sample code I am using:
function mybtn:collision(event)
if event.phase == “began” and event.other.MyName == “redbtn” then
InvItem2:removeSelf()
InvItem2 = nil
InvItem1 = createItem(“assets/interact/buttonyellow.png”, 64, 64)
InvItem1.x = 255: InvItem1.y = 710
InvItem1.MyName = “yellbtn”
print (InvItem1.MyName)
end
end

Thanks for your time. [import]uid: 133581 topic_id: 31877 reply_id: 128020[/import]

I figured this one out! I had to add a timer delay to it. It tried to access physics during the collision and it was giving me an error, but continuing and running the code. However, the variables I set up (immediately afterwords) were not assigning/registering correctly. [import]uid: 133581 topic_id: 31877 reply_id: 128045[/import]