Discuss Scratch

--Cloud--
Scratcher
12 posts

Scratch functions can't return values! Please add!

So, here's my background in programming (in case you want to hear about it):

When I was 7, my dad showed me this thing called “Scratch”. He didn't even tell me it was programming, I think he was keeping that a secret, for at that time I thought programming was something only experts were capable of doing. I found this whole “Scratch” thing incredibly fun, and created a few projects! I kept using Scratch until I was around 8. Then my dad bought by a programming book about Python. Nowadays, I think Python is way more powerful then Scratch, and can do far more things then Scratch can do. I learned about classes, functions, modules, making games using PyGame. It was so much better then Scratch because it is easier to kick up a text-based game using less code. It was easier to make a text-based game because there were lots of things Scratch didn't have: Functions with return values, classes, modules, etc. I still thought that games graphical games in Scratch was easier. Nowadays, I code in Python, JS, HTML/CSS, Ruby and C#.

However, I believe that Scratch will improve. The main thing that Scratch is missing is return values from functions.

If you are new to programming and don't know what returning a value means, I'l try to explain.

Basically, when you call a function (use the function), you can pass in parameters. However, in real programming languages, functions are much more flexible. You can take in information AND pass out information to whoever called the function. This is called returning.

Please add this to Scratch, I believe Scratch will be awesome!

Also, it's kind of annoying to hack into the project.json file when you want a drop-down parameter on a custom function, so can Scratch make this easier? Thanks!

Happy C0D1NG!

Last edited by --Cloud-- (March 11, 2017 16:47:42)


Quote by –Cloud– The only reason I stay on Scratch is because of the wonderful community… And once you have a wonderful community, it is impossible to dissolve it…
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

Scratch functions can't return values! Please add!

I agree that value-returning functions would be very useful! However, your topic really belongs in the Suggestions forum and a duplicate exists, anyway: Better Custom Blocks.

Last edited by gdpr533f604550b2f20900645890 (March 11, 2017 16:51:07)

_nix
Scratcher
1000+ posts

Scratch functions can't return values! Please add!

You could try using a list to store return data:

when gf clicked
delete (all v) of [value stack v]
append value [3]
append value [7]
add last 2 values
say last value

define append value [value]
add (value) to [value stack v]

define add last 2 values
set [second number v] to (item (last v) of [value stack v])
delete (last v) of [value stack v]
set [first number v] to (item (last v) of [value stack v])
delete (last v) of [value stack v]
append value ((first number) + (second number))

define say last value
set [string v] to (item (last v) of [value stack v])
delete (last v) of [value stack v]
say (string) for (1) secs

The gist of that is that whenever you want a function to return something, you just append that to the “value stack” (the list you store values in). When you want to use one of the values, you take it off of the value stack (“delete last”) and store it in a variable (“item last”).

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
Paddle2See
Scratch Team
1000+ posts

Scratch functions can't return values! Please add!

Chibi-Matoran wrote:

I agree that value-returning functions would be very useful! However, your topic really belongs in the Suggestions forum and a duplicate exists, anyway: Better Custom Blocks.
Thanks for the link! It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place.

Please use the existing topic in the link above.

Scratch Team Member, kayak and pickleball enthusiast, cat caregiver.

This is my forum signature! On a forum post, it is okay for Scratchers to advertise in their forum signature. The signature is the stuff that shows up below the horizontal line on the post. It will show up on every post I make.
(credit to Za-Chary)



;

Powered by DjangoBB