0 votes

I'm making a point and click game, and I'm trying to make items be combined.

I would like to combine items from my inventory (item list) with: other items on inventory and / or items on the scene.

Is it possible?

Godot version 3.4.3
in Engine by (28 points)

1 Answer

0 votes

of course it is possible and there are many ways to implement this. Do You have any scene setup and code for now ? Basically You could just design match statement for all interactions of items and their results, or use exported dictionary that will define interactions with certain items, for example :

Node Candle
var interactions = {"fire" : "burningcandle", "string" : "candleon_string"}

when item collides with another, it will iterate through this dictionary and check if something new should be instantiated

by (5,651 points)

I have started the coding, made some libraries on a Global singleton and they are called on each room/scene.
I have to admit this is the first game I aim to do without any tutorials and i feel a bit stuck atm.

Where would you suggest adding the variable for the candle?

This is my spaghetti code :)

In the global file, i have a dictionary for the dialogs (to unlock items/passages) and for the items (to be picked up and added to inventory).

var Data = {
"Collected Objects": [],
"Texts": [], 
"Unlocked_Doors":{  "Alchemy Lab Door": false,
                    "Corridor01 Door": false,
                    "Corridor02 Door": false,
                    "Corridor03 Door": false,
                    "Corridor04 Door": false,
                    "Corridor05 Door": false,
                    "Kitchen Door": false,
                    "Outside Door": false,
                    "Room05 Door": false,
                    "Room08 Door": false,
                    "Secret Room Door": false,
                    "Secret Society Door": false,
                }
                # {} =  Dictionary, set of data that contains info, strings, lists, other dictionaries [] = List 

var Game_Objects = [
                        "Cane", 
                        "Doc Coat", 
                        "Empty Jar", 
                        "Filter Jar", 
                        "Firefly", 
                        "Game Piece 1", 
                        "Game Piece 2", 
                        "Game Piece 3", 
                        "Gold", 
                        "Ingredient A", 
                        "Ingredient B", 
                        "Ingredient C", 
                        "Ingredient D", 
                        "Ingredient E", 
                        "Jar Blue Filter", 
                        "Jar Glow Fireflies", 
                        "Jar Glow Urine", 
                        "Loaf Bread", 
                        "Mandolin String", 
                        "Medallion", 
                        "Potato", 
                        "Potion", 
                        "Recipie", 
                        "Ring", 
                        "Rock", 
                        "Scroll", 
                        "Soup", 
                        "Urine"
                    ]

On each room I have called this action to check if the item is there, then add it to the itemlist and show an image of it and remove it from the scene.

func remove_objects_from_scene():
if Global.Data["Collected Objects"]:
    for item in Global.Data["Collected Objects"]:
        remove_item_from_scene(item)
if Global.Data["Texts"]:
    for item in Global.Data["Texts"]:
        remove_item_from_scene(item)



func remove_item_from_scene (item):
    for child in self.get_children():
        if item == child.name:
            get_node("./%s" %item).queue_free()

If I understand correctly,each of your item is a node, childed to the scene or to some kind of inventory when they are collected

I would keep var interactions in this item node. I suspect You use inherited scene or class script for all of them ? If Yes, than introducing this dictionary as export comes in handy.
So every item will have var interactables, that You will modify to your liking in editor, so every item has individual values - defining what it can interact with, and what will be the result of interaction.

You surely have some kind of code, to pick up an object from inventory and click another one, to combine it. This is where You should iterate for var interactables content. Like in this pseudocode :

on_item_being_tried_to_combine_with_another ( anotheritem) :
      for entry in interactables.keys() :
             if anotheritem.name == entry :
                     createnewitem(interactables[entry])
                     removefrominventory(self)
                     removefrominventory(anotheritem)
                     return

      printmessage("these items can't be combined")

Thank you, I will try to implement this section!!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.