2

I am just starting to play with this as an educational tool for a youngster and encounter strange behavior whilst attempting to clone sprites.

I setup a global variable for position x,y in sprite_1 and clone a sprite_2 object. This object immediately copies the global x,y to local x,y and exits. Later sprite_2 renders using the stored local x,y.

sprite_1:

enter image description here

sprite_2:

enter image description here

I expect the four sprites to clone diagonally up/right on the screen according to this small reproduce-able example. Instead I appear to get four sprite_2 objects all on top of each other:

enter image description here

If I add a delay of 1 second onto the end of the clone(x,y) function however all is well:

enter image description here

enter image description here

As all four sprite_2 objects appear to be where the last clone was placed, I have a suspicion that the clones are not created immediately but instead created as a batch all at once, at some time and therefore are all taking the last coordinates from the globals _clone_enemy_x/y.

Is this the case? is there are way to circumvent this behavior or what is the solution?

Chris
  • 2,655
  • 2
  • 18
  • 22
  • Can you try just adding a `wait (0) secs` instead of a `wait (1) secs`? I have a feeling this is just a race condition, and I'd be interested in seeing if that fixes it. – Mithical Nov 30 '17 at 14:12
  • Interestingly I had tried 0 in my project and it did not work, however I tried it in this simple reproduction and it succeeded. I then put the clone(x.y) in a loop of 50 and it still worked. Which means you have the solution for the immediate issue, and I may have a bug in the project, or the race condition in the full project is not resolved because of workload (the project features scroll and starscreen) – Chris Nov 30 '17 at 17:33
  • Could you possibly share a link to the project (and share the project)? I'm now curious if there's anything else that may be influencing this. – Mithical Nov 30 '17 at 17:38
  • I'm not ready to share it yet, so ill hold. I worked around the issue by changing how I spawn. In the sprite which wants to induce the spawn, I send a msg. I answer the msg in the sprite to be spawned. I can create many back to back using create clone of self. Cheers for the help though. – Chris Dec 04 '17 at 04:46
  • This looks like the same issue as my question at https://stackoverflow.com/questions/42984298/a-grid-of-clones. It was answered clearly by @PullJosh. – Jim K Jan 04 '18 at 22:09

1 Answers1

0

I have 2 possible solutions to this problem:

  1. Go to the "define clone()()" block, right click it, open up the advanced dropdown, and tick "run without screen refresh".
  2. Get rid of the custom block all together, but use the original source for that block in the actual code.

I hope this helps!

Harry
  • 1
  • 2