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

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

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

:bust_in_silhouette: Reply From: Help me please

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

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 ?

szccornish | 2021-06-14 20:51

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.

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

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

Help me please | 2021-06-15 14:34

:bust_in_silhouette: Reply From: Wakatta

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

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

Wakatta | 2021-06-12 14:22