What does the return 0 block does

There is a circle version of every function that has a return block in it - look closer in the functions tab

isn’t a circumference of a circle Diameter x pi
and radius radius^2 x pi

@UnsignedArduino

Here is your code that contains my question:

This is what I meant:

1 Like

You are right. I didn’t see that under functions there are two blocks for the same function. Very strange.

In the blocks UI it looks like the first function does not return a value, and the second one does.

@jwunderl
Do you know why the UI shows two functions for one function that returns a value?

For the function ‘call calculateDistanceBetweenPoits’ I can imagine there is not enough room in blocks UI to show the names of the input parameters. That is a pity, as a programmer I have no idea what 1, 1, 1, 1 means. Also, I have no idea what the function returns:

image

I guess that’s why block functions are designed for high level basic programming, to set things and not to return something.

Then again, having a block section such as ‘Points’ (x, y on screen) then you might be able to use something like (imitating the block UI)

getDistanceBetweenPoints (pointA) (pointB) : integer

@cosmoscowboy @UnsignedArduino that means the return block turns the function into those oval blocks after that?

If a function has a return block in it, it will have a circle version

There are two blocks because there are two different use cases; calling the function, and obtaining the value returned from the function. Regular puzzle piece blocks are statements that can be used on their own, but round ones cannot.

For why you would need both; you might make a function that creates a sprite on the right side of the screen, and call it several times. Later on, you need access to the sprite that you made, so you make the function return the sprite / create the round block in the toolbox. You don’t want to have to store the returned sprite every other place that it’s been created, just in the new spot.

re: labels on the functions; that’s something we’ve discussed / is a potential future feature https://github.com/microsoft/pxt-arcade/issues/1256, but I’d note that it’s primarily the job of the function name in blocks to tell you what it returns, not necessarily any special UI – in this case, calculateDistanceBetweenPoints is stating what it’s doing but not necessarily saying what’s done with the calculation, it might be more clear if the function was instead named something like distance between two points – it’s always subtle when picking names, but that’s not significantly different to how all the blocks are written anyways.

1 Like