Container/Inventory - System Template
  • CJW November 2012
    What's This?
    This is a premade "system" for choicescript games, that gives developers a starting point for basic container/inventory functionality. I actually made the core of it a while back, but stopped working on it when I realized how much of my own game devving time it was taking. Today I sat down, saw it in my dropbox folder and decided to cut 'the fat' (unfinished features) and release it as is. Lest it go to complete waste.

    Why make this?
    Systems like this can take a long time to make in choicescript and can be a real hole in the head for newcomers in-particular. I tried to write this so that - almost - anybody could add an inventory/container like system to their games without too much hassle, as it's a one of the more popular desires/requests we've seen and will probably continue to see.

    Credit?
    Same as always: Credit is very much appreciated, but not strictly necessary.
    Feel free to modify/share and use this code to your heart's content.

    Support
    - I WILL try and fix any bugs with the current upload, assuming any are found.
    - I WON'T fix bugs related to your OWN additions or modifications to the system.
    - I don't currently plan on implementing any more features. This already took up way too much of my time.

    If you have any questions, just ask them. Whilst the above holds true, it's not set in stone.
    If you have a really simple problem and I know the answer, I'll always help as best I can. I just don't want to be spending hours and hours fixing problems other people created (who would?).

    Remember: The best way to learn is from amending your own mistakes.

    Key Points
    • You can activate/deactivate items and containers at any time.
    • You can change the name/size/location(item only) of an item/container at any time.
    • The system is wrote ENTIRELY in choicescript (with defining mygame.js variables), there's no "hacking" or raw j/s use.
    • You only need copy and edit the item/container variable definitions in mygame.js, add a single #choice definition in startup.txt and update the total number of items/containers variable.
    • The majority of the on-screen information text is configurable via variables in mygame.js
    • It supports an unlimited* amount of items/containers.
    • The downloadable scene file code is about 400 lines long.
    • You can change a specific item/container details during your game via variable setting, or call custom label routines to change a number of items/containers at once.
    • The system is NOT designed for multiple instance items, they need to be unique. They also need to be defined in mygame.js. You can't create new items/containers during the game.

    *Within reason

    Tutorial, Demo and Download Link
    Download: https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/inventory-system/system-containers-lv.zip
    Demo: https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/inventory-system/index.html
    Basic Tutorial/Guide (Read. It.): https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/inventory-system/tutorial.html
    Choicescript Code: https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/inventory-system/scenes/startup.txt
    Variables/Mygame.js: https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/code/inventory-system/mygame.js

    If nothing else I hope maybe this will inspire people to be a bit more ambitious with their choicescript coding!
  • VendettaVendetta November 2012
    If I had to sum this up in one word it would have to be . . . "Wow!".

    Seriously, I have to take my hat off to you. It's probably the most advanced bit of pure-ChoiceScript code I've ever seen, and it does stuff in a way that I simply didn't think would be possible without resorting to JavaScript. Kudos.

    It must be said, at first glance it looks way too complicated! However, upon closer inspection, it soon becomes clear that the apparent complexity is really just in-built adaptability, as (unless I'm very much mistaken) it has the potential to be put to a variety of uses. The basic system itself is actually pretty straightforward and is little more than a case of deciding which settings you want to use for your game, and how you choose to word different things. Once you get your head around that, everything becomes much clearer. :D

    I sincerely hope that the sheer adaptability of this doesn't put anyone off using it. I've already spotted one potential use for it in Vendetta (nothing at all to do with named 'containers' per se, despite that being its primary purpose--which demonstrates its adaptability!) and I can envisage future uses where this system could actually provide much of the backbone to a game.

    One for the Wiki, I hope? It'd be a crying shame to lose this work of art under the sheer weight of forum spa... erm... topics!
  • WiReDcHiMpAnZeEWiReDcHiMpAnZeE November 2012
    Lol @vendetta! And yeah once i study this ill work on incorporating it into my games.
  • lordirishdaslordirishdas November 2012
    @CJW what can I say, you rock.
  • P_Tigras November 2012
    @CJW

    I wrote an inventory system in pure choicescript a few months back. It will be interesting to see how yours differs from mine. If you found a way to define variables via a loop in mygame.js I'll be most pleased. It was a royal pain in the backside to explicitly define each and every element in my faux arrays.
  • ReaperoaReaperoa November 2012
    Well, apparently Jason liked it. All I can say is that it's unfortunate that I currently have no need of something such as this at the moment.
  • P_Tigras November 2012
    @CJW

    Very nice work. You took much more of an object oriented approach than I did. Your implementation is a bit more complex to set up than mine, but also a bit more flexible. I was only concerned with adding/removing/checking/displaying the objects in the player's inventory and ensuring their total weight didn't exceed the maximum. Yours keeps track of the location of each item in the game even when they're not in the player's inventory. And of course each location is a separate "container".
  • CJW November 2012
    Wow...

    A sticky... !? Now I feel a little nervous ^^'
    I wasn't expecting that level of response!!!
    Thank you!

    @WiReDcHiMpAnZeE
    Sounds good!

    @Reaperoa
    He made it an announcement? :o
    It'll still be here if you ever change your mind!

    @lordirishdas
    Thanks?! :)

    @Vendetta - Wiki? Definitely? Implementation into Vendetta? I'd love to see it, and I'm glad you picked up on how versatile it is. "Containers" and "Items" are just names, you may as well call them presents and wrapping paper. Anything that goes inside anything else. :D

    @P_Tigras
    I'd love to see it! Always good to compare and contrast, swap improvements.
    Sadly without resorting to custom commands or raw javascript it's completely impossible to create dynamic objects or variables in choicescript.
    If you search for eposic's "object" code though (set of custom commands), with that it is possible to create stuff on the fly.
    I personally wanted to do this without any kind of extra hacking, in any way shape, or form.

    I really did try to make it as multi-purpose as possible, hence the final lack of features.
    It's more of a template than anything.

    But if you think about it, a container can be absolutely anything! Even in one game you could have "items" 0-20 being characters and 21-50 being items, 0-10 containers being houses.

    Then you can put people and items inside houses (choicescript SIMS anyone, lol?).
    If you're feeling adventurous you could then extend the code to look for a new parameter/attribute on "items" that differentiates items and humans, if you were so inclined.

    ----

    You can also 'wrap' smaller systems round it.
    For example, I originally planned to implement the shop and cost parameters to allow some containers to be considered "vendors" but have sinced realized it'd be easier to "wrap" shops around the container functions.


    *label myShop
    *choice
    #Buy Arvan's Sword
    *if (gold > 20)
    *set gold (gold - 20)
    *set item_54_location 1
    You bought Arvan's Sword!
    *comment This item will now appear in your inventory (the default id for which is '1')!
    *goto myShop
    You do not have enough gold!
    *goto myShop
    #Buy all Ten Potions
    *if (gold > (10*potion_price)
    *set gold (gold - (10*potion_price)
    *set para1 20
    *set para2 30
    *set para3 1
    *gosub function_changeItemRangeLoc
    You bought all ten of Arvan's potions!
    *comment items 20-30 (our potions) are now in our inventory (container '1')
    *goto myShop
    You don't have enough money!
    *goto myShop


    EDIT:
    If you're feeling really adventurous you could have a temp variable hold the the number of potions remaining, and allow the purchase of 1 at a time through its manipulation:


    *temp potion_count
    *set potion_count 10
    *temp current_potion
    *set current_potion 20
    *label myShop
    *choice
    #Buy 1 Potion
    *if (gold > 20) and (potion_count > 0)
    *set gold (gold - 20)
    *setref ("item_"&current_potion)&"_location" 1 //- Syntax "might" be wrong here
    *set current_potion (current_potion + 1)
    *set potion_count (potion_count - 1)
    You bought a potion!
    *goto myShop
    *if (potion_count > 0)
    You don't have enough gold!
    *goto myShop
    *if (gold > 20)
    There are no potions left to buy!
    *goto myShop
    You don't have enough gold and there are no potions left to buy!
    *goto myShop
  • CJW November 2012
    To save people using the awful set syntax I coded/adapted functions for external use, namely:

    function_getContainerByName
    function_getContainerSize
    function_getContainerActive
    function_getContainerName
    function_getContainerSpace
    function_getContainer
    function_getItemByName
    function_getItemSize
    function_getItemActive
    function_getItemLoc
    function_getItemName
    function_getItem

    All the functions use the variable "take_value" as the argument.
    i.e.

    *set take_value 5
    *gosub function_getItem

    Will 'get' item number 5

    Everything but getItem and getContainer return the value (getItemLoc returns the id of the container its in, getItemName returns the string/name of the item etc) in the variable ${return_value}

    getItem and getContainer GET all an items properties, so return several values in the following format:

    container_[var]
    or
    item_[var]

    Where [var] is the particuar value returned, e.g.:

    *set take_value 5
    *gosub function_getItem

    ${item_name}
    ${item_active}
    ${item_size}

    Etc...

    I also added several custom error messages related to those functions, optimized some code, changed some variable names and generally made things tidier. I also added several comments about what many functions take/receive and do.

    A more detailed explanation for each function and the take and return values is on my TODO list.

    To get the new changes please use the code link:
    http://dl.dropbox.com/u/7840892/system-containers/mygame/scenes/startup.txt

    And the mygame.js link:
    http://dl.dropbox.com/u/7840892/system-containers/mygame/mygame.js

    As I've yet to update the mediafire file.
    Thank you!
  • ReaperoaReaperoa November 2012
    @CJW If you want to update the original post, PM me the new post and I can do it.
  • CJW December 2012
    @Reaperoa - Thanks!
    Could you add this link in place of the mediafire one for the general .zip download? I figured I could actually update it constantly without bothering you too much if the link is dropbox hosted.

    https://dl.dropbox.com/u/7840892/system-containers/system-containers-lv.zip

    lv = Latest Version - Which now contains all the updates I mentioned in the post above.
  • ReaperoaReaperoa December 2012
    @CJW Done.
  • CJW December 2012
    Thank you!
  • RainsfordXYRainsfordXY December 2012
    Well done.
  • CJW December 2012
    @RainsfordXY Thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter Sign In with Google Login with Facebook

Sign In Apply for Membership