Where will it return 0 to
is it almost like a repeat block or something
will the text be 0
It will first call return_zero
, which returns 0. That gets passed to convert _ to text
, which takes that 0 into “0”. Finally It takes that “0” and passes it to show long text, which displays 0
Yes you are correct!
Today, I have learned what a return block does, almost
Do you have any other cases where you don’t understand?
Or any questions?
Oh jeez, I’m starting to sound like a teacher
I should bookmark this conversation so I can come back to it
You feel like a teacher to me
Those functions I showed you, they also use the return block
I’m so sorry, I going overboard with this
nah it was me for asking all those questions
I understand most of it. I think I know how to use it now
Nice!
The knowledge you learned today will help you write much cleaner code.
If you ever have questions, just ping me. I should respond within a day.
The knowledge you learned today will help you write much cleaner code.
Sounds like it came directly out of the “How to speak like a teacher” guide
Lots of great discussion in this thread! One other thing that I think is important to note is that you don’t have to just return numbers; you can return any value you have! For example, this code has a create my enemy!
function that creates a special skeleton:
This is like making your own blocks that create things – exactly how you would do it if you were to make your own projectile
block, or anything like that.
Oh yes, a good thing to remember. I thought you could only return numbers! (And booleans, but that’s just 0s and 1s internally)
I bet you used the numbers to change the color
The idea of returning a value from a function is great, what @UnsignedArduino mentioned (What does the return 0 block does).
However in the function that returns a sprite, the sprite is still defined outside the function (as if it a global variable), and then set within the function. See the resulting script:
let my_enemy: Sprite = null
function create_my_enemy () {
my_enemy = sprites.create(imgremoved
, SpriteKind.Player)
my_enemy.setPosition(randint(0, 60), randint(0, 60))
my_enemy.setVelocity(50, 50)
my_enemy.image.replace(1, randint(1, 14))
return my_enemy
}
Is this a limitation of block code and/or because Sprite is complex type (class)? Does this only work for simple types (int, bool, string, etc)?
I have defined a function that accept parameters and returns an integer. But I cannot use a return block that uses that function (see function calculate_distance_4
Just curious.