Hidden Object Game: Hide items on room until you have another object or spoke to someone

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TheCoinCollector

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", 
					"Game Piece 1", 
					"Game Piece 2", 
					"Game Piece 3", 
					"Glow Jar", 
					"Glow Jar Fireflies", 
					"Ingredient A", 
					"Ingredient B", 
					"Ingredient C", 
					"Ingredient D", 
					"Ingredient E", 
					"Jar Blue Filter", 
					"Loaf Bread", 
					"Mandolin String", 

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
		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:

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”.

CardboardComputers | 2022-03-14 13:53

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?

TheCoinCollector | 2022-03-15 08:39

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

TheCoinCollector | 2022-03-15 11:03