You place the exact same script on every item and just use the inspector to assign their name and number. Every object should have their own script, just like every NPC should have their own script. Because every object will take care of themselves, without the need to make code too complicated.
You can use empty nodes and place all the same objects inside, almost like a folder to help organize your scene. That way when you are designing your levels, you can always name that node Kettle_1 or Kettle_5 to stay organized.
Youâre probably going to want to place them in unique locations, because your going to have to set them on shelves or even rotate them to lean up against furniture in a unique way.
Godot has a random number generator. You set the min and max values within the brackets. Just use that somewhere when you start a newgame to assign the random value to objects on the list.
Variable = randi_range ( 1, 10 )
1 Like
There are random array/list pickers too, so maybe use a combination of both things youâve been using so far with that. You could create a function that does all this inside, so you can reuse this when starting a new game.
Have your Player List and a complete Item List. Then use the random array picker to remove a random item from one list, but at the same time set the name on the Player_List and set the value to true on your Key_List. You do this for how many items you want.
The rest of the items should start with a value of false. So that entire list can be used to check whether an item exists on your Player List or not. Then use the true/false to delete themselves within the scene.
You can also uses classes to store information easier. They can also make things easier when you want to reset something. You can use them like variables to help with organization.
class_name Database
static var ScoreCount : int = 0
static var Key_List = { "Key_One": KeyBase.new(), "Key_Two": KeyBase.new() }
class_name KeyBase
var Key_Check : bool = false
var On_List : bool = false
var Random_Check : int = randi_range ( 1, 10 )
class_name KeyItem extends Node
@export var Item_ID : String
@export var Item_Number : int
var Current_Item : KeyBase :
get : return Database.Key_List[Item_ID]
set(value) : Database.Key_List[Item_ID] = value
func _ready():
if Current_Item.Random_Check != Item_Number:
# Delete object
elif Current_Item.Key_Check == true:
# Delete object
func Pickup():
if Current_Item.Key_Check == false and Current_Item.On_List = true:
Current_Item.Key_Check = true
Database.ScoreCount += 1
# Play Animation
# Delete object
This way you take an entire class and save it within your resource folder, then use that to make your own custom variables, that hold other variables. You set these when you start your program, but you can also reset these classes with the exact same line.
func Reset_Key(item_id):
Key_List[item_id] = KeyBase.new()
func Change_Check(item_id):
Key_List[item_id].Key_Check = true
1 Like
Updated so Pickup has an âandâ condition.
1 Like
Have your Player List and a complete Item List. Then use the random array picker to remove a random item from one list, but at the same time set the name on the Player_List and set the value to true on your Key_List.
Could you please show me how you can do this? I got stuck on this part.
I started Godot last week, so these things are new to me too. You could probably use the array shuffle, clear and add methods. It might look something like this.
func New_List():
Item_List.Shuffle()
Player_List.clear()
Player_List[0] = Item_List[0]
Player_List[1] = Item_List[1]
Player_List[2] = Item_List[2]
Actually, you could probably just do this with one list. Just use the shuffle function to randomize the entire Key_List. But only use the first slots with your sheet of paper, while the other ones arenât even used. Reset the entire list, when you start a new gameâŚ
class_name Database
static var ScoreCount : int = 0
static var Key_List = { "Key_One": KeyBase.new(), "Key_Two": KeyBase.new() }
func Shuffle_List():
Key_List.Shuffle()
Key_List[0].On_List = true
Key_List[1].On_List = true
Key_List[2].On_List = true
class_name KeyBase
var Item_Name : String
var Key_Check : bool = false
var On_List : bool = false
var Random_Check : int = randi_range ( 1, 10 )
class_name Menu extends node
var Key_One : KeyBase :
get : return Database.Key_List [0]
set(value) : Database.Key_List [0] = value
var Key_Two : KeyBase :
get : return Database.Key_List [1]
set(value) : Database.Key_List [1] = value
var Key_Three : KeyBase :
get : return Database.Key_List [2]
set(value) : Database.Key_List [2] = value
Then use those get/set values to view data on your piece of paper.
if Key_Three.Key_Check = true
# Cross off list