How to set the value of a variable that resides in a collided body?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Strange topic description perhaps, I’ll try and elaborate clearly:

I have a collision event in a script called ball.gd. It’s attached to my ball.tscn file. Within ball.gd I have received the name of the body the ball has collided with. Like so:

var entity = ball.get_collider()

The entity is actually a brick, in my game of Breakout. It’s an instanced scene of course. The brick has a variable built into it. The variable is called numOfHitsRequired

I’ve tried things like entity.numOfHitsRequired = x and other things but I just can’t seem to set the variable. I want to reduce the numOfHitsRequired variable WITHIN the entity I’ve collided with so the brick.gd can handle itself as required. There are hundreds of bricks so I’m trying to deal with the one that’s been identified in entity.

Any advice would be really appreciated.

EDIT: I’ve researched further and realised get_collider() returns the BODY that the item collided with. So that would explain why entity.numOfHitsRequired = x doesn’t work. I’m still lost though. Just a little prod is all I will need I’m sure. Thanks again.

:bust_in_silhouette: Reply From: Robster

I just found it. For anyone in the future.

My scene was setup as:

brick
- sprite
- StaticBody2D
-- CollisionShape2D

So I simply had to call entity.get_parent().numOfHitsRequired = x. It was the PARENT I had to call.