Editor issue changing sprite default animation

Hi, i

I’m not sure if im doing this wrong or not but doesnt seem right, will provide screen shots at the bottom.

Lets say I have 10 enemy objects on screen, all have there own sprites etc.

If I go to change 1 of them to a different default animation in the editor, it auto changes ALL of the other 9 to the same one, the same happens if I change anything on the sprite or even to test deleted it, it deleted all the other 9 from the other objects, is this what its supposed to do?

this is my setup, if I change anything on this sprite for enemy0
sprite1

it then updates ALL of the others in the screen when I only clicked on enemy0 to change

even if I manually deselect them all again, as soon as I change anything it just does it on all of them

thanks

found a way around it by storing the default animation as a go.property then changing it on init() but not sure if there is still a way to do it directly above in the editor

What I do is using a Factory, and that’s the script I put in the Object the factory create that decide what properties it have, like name or sprite :

	-- Create rotation of star
	local vitesse = math.random(1, 10)
	self.speed = vitesse
	go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 60/self.speed)

	-- Set colour of star
	local couleur = math.random(1,7)
	couleur = liste_etoiles[couleur]
	msg.post("#sprite", "play_animation", {id = hash(couleur)})
	lua_ecrire_systeme(self.id, "couleur", couleur)

	-- Give it a name
	local name = systeme_nom_liste[self.id]
	lua_ecrire_systeme(self.id, "nom", name)

lua_ecrire_systeme is a function that write in a global Table the data of the Object, here the stars systems in a 4X I 'm working on. The function is in a LUA script the Object script don’t even have to call for… reason (maybe because the script that call the factory already do it, I don’t know).

1 Like

looks interesting thanks will give it a try, im still very new to lua / defold but enjoying it so far.

The global table thing looks very useful will check that out as well thanks

1 Like
-- Enter data in the Solar System table. id is the System number, message_is the name of the data, messsage its value
function lua_ecrire_systeme(id, message_id, message)

	if systeme[id] then
		systeme[id][message_id] = message
	else
		table.insert(systeme, id, {[message_id] = message})
	end

	
end

-- read and send back a value in the Solar System table. message_id is the name of the data wanted.
function lua_lire_systeme(id, message_id)

	if systeme[id] then
		return systeme[id][message_id]
	else
		print ("systeme[".. id .."] not exists")
	end
	
end
1 Like

And here the code from the on_message function in the Object factori’ed (the star), that message another script (this one from the cursor, that centralize inputs and is in the Object that collisioned with the star), tell it something colisioned with it, and if you click now it will be on this Star.
Send its game ID in the “id” variable :

function on_message(self, message_id, message, sender)
	
	if message_id == hash("trigger_response") then
		if message.enter then
			
			-- take action for entry
			go.set_scale(2)
			msg.post(message.other_id, "etoile_click", {click = true, id = self.id})
		else
			-- take action for exit
			go.set_scale(1)
			msg.post(message.other_id, "etoile_click", {click = false, id = self.id})
		end
	end
	
end
1 Like

thanks for all the help will have a go at adding some of it once i finish work :slight_smile: