Block not working as expected

I’m making a custom block and I can’t seem to get it to work as it should


For some reason when the code runs, the main sprite runs it instead of the new clone, in fact it never makes a clone at all
“Sprite” is the sprite drop-down list
“Item” is what it should report
“Stack” is the block stack below it

Can I have some help?

This is what the block looks like on the outside
What it should do is report (in this case) what direction would be after running the code in the c block and then after deleting the clone
Thing script pic 4
But instead the main sprite runs the scripts inside and a clone is never created

A clone is made, it’s just deleted immediately like it should be

But I can’t see why the main sprite does the script despite it telling the clone to, the variable is set before the clone is deleted so it’s probably not that, but still that wouldn’t explain why the main sprite runs it

Since you're putting in the direction before, it will set B to the direction it was at before Stack was ran. To fix this, use a ring, or unevaluated input, then call Item after running Stack. Also, the clone is indeed running the script.

I don’t understand really, shouldn’t clones inherit block variables?

Clones don't, but grey rings do. You should be fine just setting B instead of telling Sprite to set B.

Yes, it’s supposed to not set it

This is the improved script


The main sprite still runs the code instead of a clone running the code, setting the variable, then deleting and reporting the value from the clone

I think I understand there is an issue, but I don’t understand why the main sprite still runs the code

the clone does run the code, but the code does the actions to the main sprite, because the ring was created by the main sprite, and the ring keeps the variables of where it was created. things like position and direction are treated like variables.

with tell (sprite) to (ring), the ring uses the variables of that sprite, same with (ring) OF (clone). the problem here is that inside that you have RUN (Stack) and CALL (Item), and those rings are created by the main sprite. use TELL or OF on those too.

I revised the code
Thing script pic 6
All works as expected now, apart from the main sprite running the script

I see why the sprite is running the code. This has to do with the block context. You see, when you put a block into a ring, it remembers what sprite it was created in, then when you run it, it runs the script as if it were in the sprite. To make the clone run the script, you need to tell (my [self] to (Stack) ((my [self]) reports the sprite (or clone) that is running the script).

untitled script pic
i would do it like this. i left the WARP out because that doesn't work for all code and often isn't necessary anyways.

Thank you! I didn’t think of setting it to a variable! That makes more sense

It doesn't work for me (return 0 instead of 105)
image

You have to turn the item parameter to "reporter" or "any unevaluated" and after this, it work...
image

image
@cookieclickerer33 : This block will be usefull, thk for the idea!
last version:
untitled script pic

by the way, you can report something like this:
ask sprite for __ after you hypothetically run this code-cookieclickerer33 script pic

Works fine for me, I’m not sure why it doesn’t for you

Also, yes I did think about this myself mainly when I was creating a physics engine, I thought it would be useful for testing if a collision would happen next frame, I also plan of making an entire series of custom block

i thought i had set it to any unevaluated

edit: agh i just came back after a while i didn't check the date

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.