How do i CREATE A ONCE BLOCK

I want to make a block that mostly returns false, but when something is true, it only returns true for 0.01 secs then goes back to false.

<once <> :: operators>

idk im new sry :((( ill get my friends to help

If do you want to make an "once" custom block, let us make the definition for it:
untitled script pic (3)
The block variables make sure that the selected block has one of its inputs changed.
Remember folks, you have to do a right click on every block to see a menu according to those. :~)
Any block variable will not have a default value, instead you have to put it with your own rules.
untitled script pic (2)

why is the input a λ ring instead of a ? boolean

perhaps you didnt check the post. [scratchblocks]<once <> :: operators>[/scratchblocks]

In this case, the "λ" one is for boolean (unevaluated). "λ" means about being inside a ring.
The "λ" is the best option for calling blocks inside rings. But booleans and text can be inside too.
Our mentor Brian Harvey (co-creator of Snap!) said that everything is first class. :~)
"? boolean" is for booleans but being evaluated before the execution of the block.

ok

I tried runnig this script
Snap!+ script pic
when i turned z false, it worked as expected, but when i turn z true zz didnt become true, then false after 0.01 secs, it just turned true and didnt turn false until z was false

Snap!'s variables change instantly, but the rendering
is delayed for that time to not use so much energy.
About the "once" block... I did not expect more than just that. :open_mouth:

what i expected:

false: after 0 secs: false, after 0.01 secs: false
true: after 0 secs: true, after 0.01 secs: false

what i got:

false: after 0 secs: false, after 0.01 secs: false
true: after 0 secs: false, after 0.01 secs: true

Here's my way of doing it.

The input does not need to be unevaluated, because it's already being evaluated every time you run the block (and that's what you're doing manually, which is redundant). Not to mention, values can be true, even if they're not a boolean, so you can't just check if the value equals true (but you can just stick the variable into an if block). Now, my if else checks are actually basically just the same as yours, I just merged the nested if else block with the outer checks.


@theaysnap The way this block works, is by only reporting true the first time it was true, and then returning false until it becomes false and then true again. The easiest way to see this, is by clicking on the block a bunch of times.

1000430065
1000430066
1000430066
1000430067
1000430065

There is no timing going on here (because that's just not very good, but this is basically what you were asking).

Like what @alessandrito123 said, variable watchers do not update immediately, there is a very noticeable delay, so you can't just test something like this by putting it in a forever loop and looking at the variable on stage, however you can put a say block under the block that sets the variable to see it update in real time.
1000430068

Oh by the way, you can actually drag and drop a script pic from the forums into snap to get the script in the image without needing to recreate the script.

it just returns the value

i think i found a way

so i made a custom var called _booleans*once, and i found a script
Snap!+ script pic (1)

I can't drag this image into snap. i tried enlarging it and using the "original image" button but i cannot import it.

@theaysnap are you sure you recreated the block correctly?

I swear i did it correctly.
Here is the xml code

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