Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Identity Script
- ScratchGuy5
-
100+ posts
Identity Script
Hello. I need a script that sets a cloned sprite to a certain x position. However, the clone is going to have an identity variable to use in a list that determines that x position of said clone. I'll show you:
Any ideas? Thanks.
- ScratchGuy5
-
100+ posts
Identity Script
I'll try to explain a little better. It's long, so bear with me.
Let's say there are two clones, let's call them Clone 1 and Clone 2.
I want Clone 1 to spawn at x:70 and y: 20 and move to an x of 110. But, I want Clone 2 to spawn at x:20 and y:-50 and move to an x of 60.
Is there anything I can do? (I'm sure you have to use lists.)
P.S. Is has to work with more than just 2 enemies.
Let's say there are two clones, let's call them Clone 1 and Clone 2.
I want Clone 1 to spawn at x:70 and y: 20 and move to an x of 110. But, I want Clone 2 to spawn at x:20 and y:-50 and move to an x of 60.
Is there anything I can do? (I'm sure you have to use lists.)
P.S. Is has to work with more than just 2 enemies.
- deck26
-
1000+ posts
Identity Script
What you have looks close enough assuming id is set properly. The script also assumes the clone is pointing in the right direction initially.
- DrummerCat
-
8 posts
Identity Script
I think I remember seeing a project about this somewhere… …I think it was called “Clone control” or something. Try creating a variable and click “For this sprite only.” It should work with clones as well. For example:
then use something like:
What you want is probably:
and
then use something like:
What you want is probably:
and
Last edited by DrummerCat (April 14, 2015 18:12:09)
- ScratchGuy5
-
100+ posts
Identity Script
Sorry for late reply. What you have looks close enough assuming id is set properly. The script also assumes the clone is pointing in the right direction initially.
Anyways, how do I set the id properly? I forgot to tell you, there's another part. This involves the spawning sprite:
Is there a way to cause the spawning sprite to select the id, and use the same id variable in this script:
Last edited by ScratchGuy5 (April 14, 2015 21:49:45)
- ScratchGuy5
-
100+ posts
Identity Script
I just thought of something! A combination of me and DrummerCat's ideas:
I'll see if this works.
- deck26
-
1000+ posts
Identity Script
This should work if all the variables are local to the sprite. However I wouldn't make the list a local one as it will be duplicated unnecessarily to all the clones. I just thought of something! A combination of me and DrummerCat's ideas:I'll see if this works.
- ScratchGuy5
-
100+ posts
Identity Script
I don't understand. I made the list exclusive to the sprite. Could you be more specific? Thanks. This should work if all the variables are local to the sprite. However I wouldn't make the list a local one as it will be duplicated unnecessarily to all the clones.
- deck26
-
1000+ posts
Identity Script
Only the sprite itself is using any of the lists in your script - the appropriate item gets loaded into a local variable which is what the clone then uses. But each clone also has a copy of all those local lists which is inefficient when the clones don't need them. Whether it makes any difference depends on the project but it is potentially confusing and could slow things down.
- ScratchGuy5
-
100+ posts
Identity Script
So… how do I fix this? Help would be appreciated. Only the sprite itself is using any of the lists in your script - the appropriate item gets loaded into a local variable which is what the clone then uses. But each clone also has a copy of all those local lists which is inefficient when the clones don't need them. Whether it makes any difference depends on the project but it is potentially confusing and could slow things down.
(I used the lists to shorten the script a lot, otherwise it would have been MUCH longer.)
- deck26
-
1000+ posts
Identity Script
Just make the lists global rather than local is enough.So… how do I fix this? Help would be appreciated. Only the sprite itself is using any of the lists in your script - the appropriate item gets loaded into a local variable which is what the clone then uses. But each clone also has a copy of all those local lists which is inefficient when the clones don't need them. Whether it makes any difference depends on the project but it is potentially confusing and could slow things down.
(I used the lists to shorten the script a lot, otherwise it would have been MUCH longer.)
- ScratchGuy5
-
100+ posts
Identity Script
Okay, I'll try that. Just make the lists global rather than local is enough.
- Discussion Forums
- » Help with Scripts
-
» Identity Script