Multiple Game Objects from one file share variables?

Hello,
I have 2 birds in my level collection both from the same game object file, just registered as one game object bird1 and bird2. For test purposes i tried to let the bird stop as soon as it hits the player. In reality both birds stopped regardless of which hit the player.

Player script checks for the hit

if message_id == hash("collision_response") then
   if message.group == hash("enemy") then
      msg.post(message.other_id, "get_atk")
      print(message.other_id)
   end
end

Print returns DEBUG:SCRIPT: hash: [/bird1.go], so that’s working correctly

bird script

if message_id == hash("get_atk") then
   cd_atk = 3 -- here I set a cooldown for the bird movement
end
if cd_atk <= 0 then
   move = go.get_position() - dif * (dt / dif_length * 450)
   go.set_position(move)
end

How did you define the cooldown variable? You should define it as self.cd_atk which results in one variable per script instance (gameobject). Now it looks like a global variable or maybe a script local variable. Please read the Lua manual in our documentation for more info on this.

2 Likes