Duplicate actor when it's being dragged away
I have a question that feels like the answer should be quite simple. I've been on a break for 7 months, which messed up the flow I started having, because before that break, I only used GameSalad for 6 months.
The case:
I have an actor (a letter tile) with lots of instances in a scene (55), each with an index self.attribute 1-55. This attribute tells pretty much all code in the actor from which row in a table it should get its information from.
This actor can be dragged away to make words. When it's released, it just stays put where it is released, which it's supposed to do. On the place it started, you still see the same letter tile, but that's static actor with only the image of the corresponding letter tile.
It seems to me, that I can make dozens of actors stacked onto the same position, carrying the same self.attribute. Tried this with a pile of three and it worked fine, three times as expected. However, there is no way that that's good practice in this case.
I got a rule in the static actor that says:
if collides with actor LetterTile
do nothing
else set game.attribute to self.attribute (the static actor uses the same row and thus has the same number in its self.attribute)
Spawn actor: LetterTile (at self.pos.x&y, in front of actor)
And I got a rule in actor LetterTile that says:
if self.attribute = 0
do set self.attribute to game.attribute
else nothing (because if it's not 0, it's one of the instances that is there at the start of the scene)
But this doesn't work
Any ideas?
Answers
I'm a little lost. You're asking about best practice but what is it you're wanting to do differently? Do you want only one letter tile to be dragged from the static area? Do you want a different way to differentiate between your instances?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
You're right, I left that bit out. The idea of the scene is simply to create words with the letter tiles. There are no correct answers, so if the user wants to drag 60 A's onto lines, it shouldn't be a problem. The user will most likely be pretty young and is free to experiment.
However, to facilitate this, the draggable LetterTile should regenerate indefinitely, at least until the scene is full of tiles. Which means that creating 150 stacked instances (which is probably somewhere around the maximum amount of tiles in the scene) per individual LetterTile should work - and it does. It also means that I have to create 150 * 55 (=8000+) instances, to make sure the user won't run out of tiles. And that's the part I referred to as something that I can't imagine to be good practice.
I'll have to create 55 instances of draggable actor LetterTile, that's for sure. The 55 instances of the static actor LetterImage are necesarry as well. I kinda hoped my question reached into already explored territory, because it seems to me that there are plenty of games in which you can drag something away and it regenerates indefinitely.
To be precise in my answer towards your question:
Do you want only one letter tile to be dragged from the static area?
Yes, that's right. But if there have to be two tiles to make it work, it'll be fine as well.
Do you want a different way to differentiate between your instances?
Not necesarrily. But right now it doesn't work... So perhaps yes.
That's the part where I disagree. You shouldn't have to pre-create any instances. You can just spawn them. You don't have to physically have 150 stacked tiles to allow the user to drag 150 tiles from that position. You just need one tile that can spawn a copy of itself.
I've attached a demo. Then only strange thing is that the spawned actor is getting displaced. I don't know why. It shouldn't be moving and I don't have the brainpower right now to figure out why that's happening.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It moves because you constrain its position to the mouse, before spawning the new one. It leaves the spawned actor where you pressed the original one.
Anyway, before I start explaining what I actually meant, I think it might be better to ask a different question.
In the demo you attached, suppose you'd have the entire alphabet in tiles. Would it be wise to create seperate actors for each letter, in that case?
Because right now, in my situation, it's just one actor that has various attributes, but only one that is set manually by me. This attribute represents the row in the table it gets its image/size/position/etc. from.
So the demo won't work, because it'll spawn the actor without the right attribute-value. Surely there is a construction to make this possible. However, I'm starting to believe that it'll be much simpler to create 55 seperate actors with virtually the same code in it. Because then your demo would work. At least, it'll work when I move the spawning part to the top