Void blocks

In programming terms, a void is a function which allows you to organize code and such.

Here's the project! Snap! Build Your Own Blocks

Here is my version: Snap! 6.9.2 Build Your Own Blocks

Nice, this is cool.

It doesn't work correctly.

I've looked at your version as well.

Try running this:

Void blocks script pic

Its supposed to say something after 2 seconds, not one.

Yeah.. because it runs as soon as it gets to that, a message is set by the callfunction block, and it doesn't reset so it runs as soon as it gets to it.. Not exactly a desired outcome.

Uhh... well what's the difference between a "void" (which makes me think of a bottomless pit) and a function?

(Sorry if this sounds silly; I don't know C-type languages, only Python, JavaScript, Scratch, and Snap!)

I've never seen it referred to as "a void." I think Wikipedia's article on void types explains what the thing is:

The void type, in several programming languages derived from C and Algol68, is the type for the result of a function that returns normally, but does not provide a result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their output parameters.

The function with a void result type is already in Snap!, though: It's the grey ring that accepts command scripts (and the run block).

But you can't name that void.

So they're pretty much command blocks?

It is like if … then …

If you're naming the voids, then it's a function declaration
I've think you've misunderstood what "void" means. It's a data type for functions that return nothing, not a function that defines a function.

I'm not quite sure, but I think slate_technologies meant something more like "you can't name the void", which, I think, is still incorrect. But you're right about

It's a data type for functions that return nothing, not a function that defines a function.

untitled script pic

You can use global variables, too.

In C-like languages, every procedure has to be declared with the type of the value it returns. So if you want a procedure that doesn't return a value, you give it a return type of VOID. So, yes, that's the same as Command blocks in Snap!.

(Procedure declarations also have to declare the types of its inputs, if any. The idea is that when you do composition of functions, the compiler compares the output type of the inner function to the input type of the outer function and gives an error message if they don't match up. One problem with that idea is that it's very hard to construct a heterogeneous list -- a list whose items are of different types.)

Oh, just to confuse you further, the word VOID is used in C with a completely different meaning when you declare a pointer variable. A pointer is the address in memory of some value. When you declare a variable that will contain a pointer, you don't just say POINTER FOO; because the compiler has to know what kind of value the pointer will point to, so that it knows the size of a value of that type, so it can arrange that FOO+1 returns a pointer to the next item in an array of that kind of value. So you say INT *FOO; for a pointer to an integer, or DOUBLE *FOO; for a double-width floating point value. To handle the case in which you need a pointer variable but you don't know what the pointer will point to, you can say VOID *FOO; which means "FOO is a pointer, but we won't know until the program is running what it'll point to."

P.S. But, I don't understand, Snap! has a perfectly good procedure definition capability! Why do you want to build your own?

I was going to say that but then I saw your post.

This is not a bump, but, I heard someone saying something about Disabling and Enabling blocks. These void blocks could work and do the job. Basically a void acts as a list of blocks that are not connected to the Green Flag Hat block, only thing is, it would always be in the code but it wouldn't run without being called.

Just saying "this isn't a bump" doesn't mean it won't bump the topic up to the front page.

I know that... :neutral_face: