- Edited
Hi, first time using this forum, and don't have an idea on what the problem might be/how to show it to you guys.
A player spawns a bullet and when it collides with a body that is in the group 'player', it applies damage to the body.
It literally worked yesterday at noon, but at night it started giving me the "Invalid get index 'damage' (on base: 'EncodedObjectAsID')." error.
Bullet damage code:
remotesync func damage(attacker: Object,receiver: Object):
print(str(attacker)+" damaged "+str(receiver))
receiver.health -= damage
print(str(attacker)+" damaged "+str(receiver))
if receiver.health <= 0:
attacker.kills += 1
#attacker.health += 30
if attacker.health > 100:
attacker.health = 100
queue_free()
Bullet spawn code:
remotesync func spawn_bullet(id,tot_recoil):
var b = bullet.instance()
b.name = "Bullet" + name + str(Net.network_object_name_index)
b.flag = get_parent()
b.damage = rifle_damage
b.position = $Bulletpoint.get_global_position()
b.rotation_degrees = rotation_degrees + tot_recoil
b.apply_impulse(Vector2(0,0),Vector2(bullet_speed,0).rotated(rotation + tot_recoil))
Bullets.add_child(b)
b.set_network_master(id)
Net.network_object_name_index += 1
"Net" is a singleton and "network_object_name_index" counts each intanciated object, adding +1 to the total count in an attempt to sync the names. I copied that from altough i didnt copy what i didnt understand, so my code isnt 100% like it.