Discuss Scratch

godman2000
Scratcher
100+ posts

Can anyone explain this please!

So i Posted a question about clones going to clones, however it took too long to answer, so i looked on reddit, and there were instructions:

“Make a variable ID_COUNTER, make it available for all sprites

When starting the project, set it to 0

Make a variable ID, make it only available to this sprite (the sprite u want to clone)

When a clone is created, set the clone's ID to ID_COUNTER, and afterwards change ID_COUNTER by 1. This way, every new clone will make ID_COUNTER go up, which means no clones will have the same ID

When a clone wants to go to a clone with a specific ID, it broadcasts a message requesting for the position of a specific ID. The clone with the ID returns the value of its position and the first clone uses it to go to that position.”

I could do all the steps except for the last one, can anyone explain what your suppose to do in the last one?

Last edited by godman2000 (Nov. 30, 2021 16:10:25)

deck26
Scratcher
1000+ posts

Can anyone explain this please!

Just use global variables - eg pass-x and pass-y. When a clone receives the broadcast and its ID matches what is required it sets pass-x and pass-y to its own position. The object that made the broadcast can then go to that position.
godman2000
Scratcher
100+ posts

Can anyone explain this please!

So how can i implement this? i am a amateur scratcher, sorry !
Konserverad_gran
Scratcher
70 posts

Can anyone explain this please!

set [ID_bc v] to [...insert whichever ID you want to go to]
broadcast [request clone location v] and wait
go to x: (x_bc) y: (y_bc)

when I receive [request clone location v]
if <(ID) = (ID_bc)> then
set [x_bc v] to (x position)
set [y_bc v] to (y position)
end
Make sure that the _bc variables are available to all sprites.

Last edited by Konserverad_gran (Dec. 1, 2021 13:03:08)

Dabman2392
Scratcher
100+ posts

Can anyone explain this please!

You can use lists and a id variable, but the variable needs to be changed before the clone is created, so the clone is assigned to that variable, then use 2 lists, one for X and one for Y, and then use the id variable to assign locations on the list.

Use Shift+Down Arrow To See All Of My S i g n a t u r e
when green flag clicked
forever
imagine ::motion
program ::sound
share ::operators
end


“Knowledge is knowing a tomato is a fruit, intellegence is knowing not to put it in a fruit salad.”

<-------------------------------------------------------------------Kumquat Protection Wall------------------------------------------------------------------->::#ff5e00

⠀Kumquat Army
⠀ ⠀⠀⠀⠀|
⠀⠀⠀⠀⠀V

Lol Can't Get To The Wall
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
(kumquat) ::#ff9100
godman2000
Scratcher
100+ posts

Can anyone explain this please!

I want the bees in my game to go to each flower continuingly, so far, that does not work (Like going to a flower, then going to the next!)

Last edited by godman2000 (Dec. 1, 2021 13:40:51)

deck26
Scratcher
1000+ posts

Can anyone explain this please!

godman2000 wrote:

I want the bees in my game to go to each flower continuingly, so far, that does not work (Like going to a flower, then going to the next!)
So do as @Dabman2392 suggested. Get each flower clone to save its current position in a list using its cloneID as the index value for its list items - clone 5 updates item 5 of the x and y lists. If the flower moves it updates those values.

Each bee than has a local variable which records which flower it last visited. It can read the x and y positions of the flowers according to that value.
godman2000
Scratcher
100+ posts

Can anyone explain this please!

Ok, will this work:
forever
set [id counter v] to [1]
glide (1) secs to x: (item (id counter v) of [x v] :: list) y: (item (id counter v) of [y v] :: list)
add [id counter] to [checked v]
end
deck26
Scratcher
1000+ posts

Can anyone explain this please!

godman2000 wrote:

Ok, will this work:
forever
set [id counter v] to [1]
glide (1) secs to x: (item (id counter v) of [x v] :: list) y: (item (id counter v) of [y v] :: list)
add [id counter] to [checked v]
end
You want to increment id-counter so it moves to the next flower. No need for a ‘checked’ list if all the bees visit all the flowers in order.

If you want the bees generally to visit the flowers - ie if one bee has visited a flower the others don't - you need a different tactic. In that case having a checked list might be useful but I'd just set it to 0 for each flower initally and set it to 1 when a bee visits the flower. Then each bee can either visit the first unvisited flower or any univisted flower chosen randomly. The best method will depend exactly what you want. Also remember that if bee 1 takes 1 second to glide to a flower and doesn't mark it as visited until than bee 2 might also decide to visit the flower in the period bee 1 is gliding.

This can all be fixed but you need to provide sufficient details.
godman2000
Scratcher
100+ posts

Can anyone explain this please!

All i want is the bees to go to each flower randomly, like they choose each one and each bee goes to different flowers.

Last edited by godman2000 (Dec. 1, 2021 14:10:37)

deck26
Scratcher
1000+ posts

Can anyone explain this please!

godman2000 wrote:

All i want is the bees to go to each flower randomly, like they choose each one and each bee goes to different flowers.
In that case each bee probably wants a separate list of flowers visited. So create a local list for that sprite. Still various ways of handling this. One method would be for each bee to create a list containing the numbers 1 to n (number of flowers) and select a list item randomly each time. Eventually each bee will run out of flowers to visit.
godman2000
Scratcher
100+ posts

Can anyone explain this please!

I go the number of flowers each time on the list, however, How do i make the bees choose a item each time?

Last edited by godman2000 (Dec. 1, 2021 14:22:33)

godman2000
Scratcher
100+ posts

Can anyone explain this please!

I also added a delete everything in flowers, x and y to everytime i restart

Last edited by godman2000 (Dec. 1, 2021 14:24:00)

godman2000
Scratcher
100+ posts

Can anyone explain this please!

Along with the fact that there would be one item, but it would be the id counters number (nvm i fixed it)

Last edited by godman2000 (Dec. 1, 2021 14:30:32)

almsha1
Scratcher
14 posts

Can anyone explain this please!

Guys pls I need hjelp. I made this code to move a sprite and that sprite have clones. I don't want the clones to follow the same code. It's a shooting game and the clones are bombs, so it just look weird.
when I receive [move up]
change y by (5)

when I receive [move down]
change y by (-5)

when I start as a clone
forever
change x by (10)
end
godman2000
Scratcher
100+ posts

Can anyone explain this please!

Do i do pick random 1 to 10?
deck26
Scratcher
1000+ posts

Can anyone explain this please!

godman2000 wrote:

Do i do pick random 1 to 10?
If there are 10 items in the list and you want to choose one randomly you can use that block.
godman2000
Scratcher
100+ posts

Can anyone explain this please!

The thing is no, The flowers will generate choosing from 60 to a 100 seconds, which means there will be more flowers and more
deck26
Scratcher
1000+ posts

Can anyone explain this please!

godman2000 wrote:

The thing is no, The flowers will generate choosing from 60 to a 100 seconds, which means there will be more flowers and more
So the bee can use the length of the flowers x list to know how many flowers there are.
godman2000
Scratcher
100+ posts

Can anyone explain this please!

What blocks should i use for that?

Powered by DjangoBB