Discuss Scratch

ScratchGuy5
Scratcher
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:
whenIstartasaclonerepeatuntilxposition=itemidofmax xmove1stepspointindirection-90repeatuntilxposition=itemidofmin xmove1stepspointindirection90
Any ideas? Thanks.
ScratchGuy5
Scratcher
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.
deck26
Scratcher
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
Scratcher
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:
whenclickedrepeatsetto createcloneofmyself

then use something like:
whenIstartasaclonegotox:xy:y

What you want is probably:
whenclickedsetxto70 setyto20 setmove xto110 createcloneofmyselfsetxto20 setyto-50 setmove xto60 createcloneofmyself

and

whenIstartasaclonegotox:xy:yglidesecondsheresecstox:movexy:y

Last edited by DrummerCat (April 14, 2015 18:12:09)

ScratchGuy5
Scratcher
100+ posts

Identity Script

deck26 wrote:

What you have looks close enough assuming id is set properly. The script also assumes the clone is pointing in the right direction initially.
Sorry for late reply.
Anyways, how do I set the id properly? I forgot to tell you, there's another part. This involves the spawning sprite:
repeattotalenemiesgotox:item?ofxspawny:item?ofyspawncreatecloneofmyself
Is there a way to cause the spawning sprite to select the id, and use the same id variable in this script:
whenIstartasacloneforeverrepeatuntilxposition=itemidofmax xmove1stepspointindirection-90repeatuntilxposition=itemidofmin xmove1stepspointindirection90

Last edited by ScratchGuy5 (April 14, 2015 21:49:45)

ScratchGuy5
Scratcher
100+ posts

Identity Script

Ba-da-Bump.
whenclickedpendownforevermove10stepsturnpickrandom-15to15degreesifonedge,bounce
ScratchGuy5
Scratcher
100+ posts

Identity Script

I just thought of something! A combination of me and DrummerCat's ideas:
whenclickedrepeattotalenemiessetspawn xtoitemenemyidofspawnx listsetspawn ytoitemenemyidofspawny listsetmove x maxtoitemenemyidofmovex maxsetmove x mintoitemenemyidofmovex minchangeenemyidby1createcloneofmyself
I'll see if this works.
deck26
Scratcher
1000+ posts

Identity Script

ScratchGuy5 wrote:

I just thought of something! A combination of me and DrummerCat's ideas:
whenclickedrepeattotalenemiessetspawn xtoitemenemyidofspawnx listsetspawn ytoitemenemyidofspawny listsetmove x maxtoitemenemyidofmovex maxsetmove x mintoitemenemyidofmovex minchangeenemyidby1createcloneofmyself
I'll see if this works.
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.
ScratchGuy5
Scratcher
100+ posts

Identity Script

deck26 wrote:

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 don't understand. I made the list exclusive to the sprite. Could you be more specific? Thanks.
deck26
Scratcher
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.
THEMOSTRANDOMPOODLE
Scratcher
3 posts

Identity Script

DONT KNOW WHAT I COULD DO
ScratchGuy5
Scratcher
100+ posts

Identity Script

deck26 wrote:

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.
So… how do I fix this? Help would be appreciated.
(I used the lists to shorten the script a lot, otherwise it would have been MUCH longer.)
deck26
Scratcher
1000+ posts

Identity Script

ScratchGuy5 wrote:

deck26 wrote:

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.
So… how do I fix this? Help would be appreciated.
(I used the lists to shorten the script a lot, otherwise it would have been MUCH longer.)
Just make the lists global rather than local is enough.
ScratchGuy5
Scratcher
100+ posts

Identity Script

deck26 wrote:

Just make the lists global rather than local is enough.
Okay, I'll try that.

Powered by DjangoBB