0 votes

This is more of a game design question then a Godot specific question.

I'm making a game similar to Rimworld where every NPC and Enemy has many properties and abilities.

What structure should I use to allow them to see something and take note of it so they can go to it later?

ie: A Hunter wanders the map... see's some apples, and in the future will know they can return to that location on the map to retrieve the apples.

I already have 'inventory' for them - where each piece of inventory is a Scene and they have a list if scenes. I used a Node2d..... not actually a list - so I guess my actual question is - should these scenes be stuffed into a Node2D or should I have been making an array or list of Nodes? (The nodes being inventory and memories).

Thank in Advanced for reading.

Godot version 3
in Engine by (97 points)

Thanks all - I'll review and try all of this in detail.

2 Answers

0 votes
Best answer

There are many ways to do this, what you want as a 'memory' can be a value stored somewhere. You can use Array, Dictionary or Variables. For example, you could do:

var Memory:Array = {
    "Apples_1" = { Global_Map_Coordinates={ Vector2(512,-256) } }
}

This nested Dictionary can be accessed by calling:

Memory["Apples_1"]["Global_Map_Coordinates"] #Would return: Vector2(512,-256)

This is a example of a data structure using dictionaries, which you can make whatever you want and nest them whoever you want. For your Hunter to 'remember' where the Apples are is easy, you access them like mentioned above, you would get the coordinates for the Apple_1.

Whoever when the Hunter will be searching for Apples? And why he would want Apples? That's where you will need a simple AI to handle that, maybe your Hunter will get Apples if FOOD < 20% MAX or HEALTH < 30% MAX.

-

OR, using your own method of having nodes as a list, maybe you could create a Position2D to them apples, and create a 'Memory' node to your Hunter, like you created a Inventory. So it can be a Inventory of Memories in a sense. :D and maybe you can add a Label inside that Position2D to reference a itemname for your Hunter.

enter image description here

So you have the coordinates of the apples from the position2D and the inventory item reference stored in the label.

by (332 points)
selected by
+1 vote

You don't even need an Array of Nodes, you can just store Vector2s of the location of the item and the name of the item.

by (6,296 points)

Using a custom class may be more manageable

class_name Memory extends Reference

var points_of_interest = []
var actions_already_taken = []
var items_collected = []

func update():
    pass

func nueralise():
    pass

NPC.gd

extends node

var memory = Memory.new()

func _ready():
    memory.update()
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.