# Identification.
var weapon_ID : int
var type_ID : String
# Collision.
var collision : CollisionShape2D
Question
I want to make an item system for my 2D shooter. The way I thought of doing this is by having there being 4 different inventory slots. Iām trying to have it so when the player presses the interact key the interact area enables for a second. When the item interacts with it would disappear and its weapon ID and type ID would be sent to the player so it understand what inventory slot it should go in, but iām not sure how to send that information over
sounds like your _on_area_entered function has a reference to the player by area, depending on how your player scene is set up you can get the player script from that variable passed in.
For example assuming the player script is attached to the Area2D
func _on_area_entered(area):
if area is Player:
area.inventory = self.type_ID
Have you confirmed if this code runs, or does it error? Does area is Player align with how you created your player? Can you share your player scene tree?
The problem is that you are checking for the area-collision but the player is the characterbody. Therefore the āarea is playerā-condition evaluates to false
i got it to work but when i interact with the item it says āinvalid get index āinventoryā (on base: ānull instanceāā and crashes.
also i changed my inventory to hexgridās method.
Base script:
@onready var player = get_node("res://Scenes/Player.tscn")
Item:
func _on_area_entered(area):
if area is Area2D:
player.inventory["ranged_1"] = self.weapon_ID