Discuss Scratch

CaffeinatedKoala
New Scratcher
1 post

Using one variable to assign different values to different clones that do not affect the other values? - Simulating Mutation

Hey everyone! I'm working on a very very basic mutation/evolution simulator; for example, I am starting by assigning a random value to the “speed” variable, and then using that to determine how many steps it moves per time period. Is there a way that I can assign this variable to many clones with different values (mutations) and use that new value to determine how fast the clone moves, both without affecting the speed of the previous one and without creating a ridiculous number of variables for every individual? I have 8 variables in all that will be mutated for each clone.

Basically, how do I use a single variable to assign different values to different clones, while at the same time keeping all of the existing data stored somewhere from all previous clones, which I could not only use to move the clone at a certain speed, but also access a value from later on? (Sorry if that isn't very clear, lmk if I need to explain more) I'm fairly new to this kind of thing, and I'm sure there's some sort of wizardry that someone would know how to do with a list.

Let me know if that needs more explanation, I'm definitely not the best at that. Thanks, and have a good day!
NeonG4
Scratcher
1000+ posts

Using one variable to assign different values to different clones that do not affect the other values? - Simulating Mutation

CaffeinatedKoala wrote:

Hey everyone! I'm working on a very very basic mutation/evolution simulator; for example, I am starting by assigning a random value to the “speed” variable, and then using that to determine how many steps it moves per time period. Is there a way that I can assign this variable to many clones with different values (mutations) and use that new value to determine how fast the clone moves, both without affecting the speed of the previous one and without creating a ridiculous number of variables for every individual? I have 8 variables in all that will be mutated for each clone.

Basically, how do I use a single variable to assign different values to different clones, while at the same time keeping all of the existing data stored somewhere from all previous clones, which I could not only use to move the clone at a certain speed, but also access a value from later on? (Sorry if that isn't very clear, lmk if I need to explain more) I'm fairly new to this kind of thing, and I'm sure there's some sort of wizardry that someone would know how to do with a list.

Let me know if that needs more explanation, I'm definitely not the best at that. Thanks, and have a good day!
You put too much detail in your question lol.
A “for this sprite only” or “local” variable has different values for each clone. When you create the clone, set the local variable to a random value.

For lists, you can use a similar method. Create a local variable, called ID, and set it to zero when all clones are deleted*. Also delete all from a list. Then, before a clone is created, change the local ID variable by 1 and add an item to a list. Finally, under a clone loop, replace the item ID with the local variable of your choice.

Does this help?

*Likely the green flag click script, could also be a broadcast/receive delete this clone
leGuyW0hasremixs4evr
Scratcher
100+ posts

Using one variable to assign different values to different clones that do not affect the other values? - Simulating Mutation

You CAN do this with a variable, but i assume its must be very hard.
Instead, you can use a list.
(Speed :: list) // this is the speed list. You said you had 8 variables, so we need 8 different values.
// Make a variable,
set [clone-ID v] to [0]
// after this, we can now do
repeat (2) // set repeat amount to amount of clones you want
change [clone-ID v] by (1)
add (pick random (1) to (your number)) to [Speed v]
create clone of [ v] //clone stuff
end
// then,
when I start as a clone
if <(clone-ID) = (1)> then
... // first clone stuff.
else
if <(clone-ID) = (2)> then
... // second clone stuff.
else
... // repeat this pattern for the amount of clones you want
end
end
i dunno if this works, but ive seen some people use this for score things.

Powered by DjangoBB