0 votes

if i want to pick up all item in my world, does that mean every single item must have code in it?

Godot version 3.2.1
in Engine by (62 points)

2 Answers

+2 votes
Best answer

It depends upon how are you picking up items. If you tell then I can give you a better answer.

If your player is area2d node and you are using its body entered signal. Then you don't need script in all items. Here player is area2d node and its body entered signal is connected to the script

var portion_1 = 0

func _on_Area2D_body_entered(body):
    if body.name == "portion_1":
        portion_1 += 1
        body.queue_free()
    #and so on

Else if your player is other body(RigidBody or KinematiBody) and item is area2d. Then yes you need script in all items

by (884 points)
selected by

which on is more preferred ? using body entered signal or the Item body is kinematicBody ( Item is area 2D).

if i use kinematicBody(Item is area 2D) on all of the item and they all have script.. does performance of my game will be lagging ?

I think there won't be lagging because all the 1000 signals won't emit at the same time but if you instance all these in the editor then it might take long to read all the codes at the runtime.
But for more surity try not instance all the items and loots at the editor but instance them during runtime with codes.
Example

func instance_item(which_one):
    var s = load("res://ItemsFolder" + which_one).instance()
    add_child(s)

Here just call this function with the item you want to instance and remember name of item should be similar to its scene's name
The way I told you was devoloped by me. So that won't be much trustworthy but will still work fine

+1 vote

No. But still recommended.

You can use groups, the nodes's name, the nodes's type, the class or the nodepath to identify what can and can't be interacted with

by (4,604 points)

You can run your entire game in a single script.

However according to OOP standards it's better to delegate and group functions with similar behavior

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.