Inventory system

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Inventory system

#16 Post by monele »

Oh I was talking of coding in general. Many coders now share things, but still, many keep to themselves or just forget to put things in public.
Another reason is that not every part of code *can* be publically released and used. Code without proper documentation or not written to be reused by others will usually not be interesting to grab.

Anyway, seems like you have a good approach for this, so let's see where this goes ^^

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Inventory system

#17 Post by Jake »

Gau_Veldt wrote:I blame that on the ability to seal everything in an archive which results in many projects that do not give any code back to help others as well as the general culture of secrecy that surrounds graphic novel design.
Hmm.

I'm not sure there's really a "general culture of secrecy", to be honest - the people on this forum in particular are typically very eager to help people out with bits of code. There's a general culture of not-wanting-people-ripping-off-your-graphics and a general culture of not-wanting-people-cheating-their-way-through-your-VN-instead-of-enjoying-it-properly, but those are totally different things. Most projects don't do anything special with the engine, and thus they don't really have any code to 'give back' outside of their game script, which it's far more understandable to want to keep secret.

Even in the wide world of general programming, people frequently duplicate the functionality of existing libraries, whether those libraries are distributed binary-only and charged for or are distributed as source under a free license like the MIT or anything in between - and I believe the reason for this is usually not because there's a culture of secrecy around programming, but for two other reasons. Firstly, sometimes people find that an existing solution isn't quite right for them, that they'd prefer to write their own which does only what they want, exactly the way they want it, rather than shoe-horning someone else's version in and adding the missing features; secondly, a lot of programmers suffer from not-invented-here syndrome - which in a lot of contexts is far from a bad thing - where they will prefer to write their own version of something so that they understand it totally and can maintain it themselves rather than having to rely on some third party to fix any bugs they find. (The beardy open-source answer to this is always "if the code is open-source, then you can always find and fix the bugs yourself" - but this always makes me want to commit violence, because being "open source" doesn't magically make the code "easy to follow and understand", so it's still sometimes better to write your own version.)
Server error: user 'Jake' not found

Gau_Veldt
Regular
Posts: 86
Joined: Tue Jun 10, 2008 8:22 pm
Location: Prince George, BC
Contact:

Re: Inventory system

#18 Post by Gau_Veldt »

monele wrote:Oh I was talking of coding in general. Many coders now share things, but still, many keep to themselves or just forget to put things in public.
Another reason is that not every part of code *can* be publically released and used. Code without proper documentation or not written to be reused by others will usually not be interesting to grab.

Anyway, seems like you have a good approach for this, so let's see where this goes ^^
It does the basics but I need to add support for use/consume and named players. The example here does the basic give/check/remove:

Code: Select all

init:
  python:
    e = Character('Eileen', color="#c8ffc8")
    MasterList={
      "food": {
        "name": "Tasty Food",
        "stacksize": 20,
        "consumable": True
        }
    }

start:
  python:
    inv=InventorySystem(MasterList)
    inv.SetMoneyName("quid")
    rc1=inv.GiveToPlayer("food")
    rc2=inv.RemoveFromPlayer("food")
    rc3=inv.PlayerHasItem("food")
    thing=repr(inv.inventories)+(" (add 1=%s rm 1=%s has 1=%s)" % (rc1,rc2,rc3))
  e "%(thing)s"
You can add a Quantity argument to .GiveToPlayer(), .RemoveFromPlayer(), and .PlayerHasItem() (the default when not specified is 1). I was showing members directly for faster debugging and you wouldn't use things like inv.inventories directly in the script. Note that MasterList may be in the init section since it is intended to be a read-only resource (similar in nature to things like character objects). This master list doesn't use groups though the internal representation does.

I'll post this now then add the use/consume and named players while I'm house-and-cat-sitting.
Attachments
inventory.rpy
Inventory System
(12.58 KiB) Downloaded 154 times

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Toma