0 votes

I am doing my first game in Godot without following tutorials (to challenge myself) as this is my first approach to programming and gaming i apologize if i provide not enough or too much information.

I want to do a hidden object game through several rooms (scenes) and need to have certain items or had a certain conversation in order to unlock the next steps.

For now, I have managed to create the layout, add the items and have an ItemList showing the items that hide from the scene by saving the data on the PC.

Considering they are 24 objects to pick on 8 room (considering 3 per room) I would like people to be able to collect only 1 or 2 per room before exploring the others.

On my Global script,
I have a variable with all the "Game_Objects" that are pickable.

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

I also added a "Collected Objects" array inside a variable called Data

var Data = {
"Collected Objects": [],

In each room, I call this array to collect the item, add it to the ItemList and hide it from the room.


Now I am trying to hide the items until an event happens (you collect an item or you speak to someone).
I manage to hide the item creating a function on each room

func hide_object(name):
var Soup = $Soup
Soup.visible = false

and it works to permanently hide it, i want it to work with interaction. i decided to use the "for" option (not sure if it is the correct way) which gives me an error
Code used:

func hide_object(name):
var Soup = $Soup
Soup.visible = false
for Cane in Global.Data["Collected Objects"]:
    if Global.Data["Collected Objects"][Cane] == true:

        Soup.visible = true
    else:
        Soup.visible = false

And the error that gives me
Error on-base Array

I am not sure if this is the best way to implement if this method or not. and i find myself a bit lost since some days on this.


Found a solution that works for items.

func hide_object(name):
var Soup = $Soup
Soup.visible = false
if Global.Data["Collected Objects"]:
    for item in Global.Data["Collected Objects"]:
        if "Cane" in item:
            Soup.visible = true

Now i will need to try it with speaking with characters.
I keep the post on as is my first one and maybe someone has a better approach that i can use instead of adding each per room :smile:

Godot version 3.4.2
in Engine by (28 points)

Glad you figured it out; however, just as a addendum, the following code

    for item in Global.Data["Collected Objects"]:
        if "Cane" in item:
            Soup.visible = true

checks if "Cane" is in the name of any items. This can be a problem if, for example, the player has collected "Candy Cane". In that case, the soup would also become visible, even if the player has not collected the "Cane". I would suggest instead using

    if "Cane" in Global.Data["Collected Objects"]:
        Soup.visible = true

to directly check if any of the collected objects are exactly named "Cane".

thank you!!
that's great advice!
This simplifies the code, I will change all the codes I have on each script to avoid any issues.
Do you know if its possible to do this option of collected objects from a global.gd or is better to leave it room by room?

I also wanted to ask, for the items not showing (or blocked doors) before speaking with someone, is it possible to use the same method? I think I will use dialogic for my dialogs.

And I thought to do another collision shape over the items that don't allow it to be picked until the conversation X happens. And in case this doesn't work I thought that I can give a hidden key/object (not showing in the inventory) that allows access to the door/item

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.