Discuss Scratch

sebitommy123
Scratcher
13 posts

Function that can return a value

This would be extreamly usefull, especially for people who don't wan't to exit the Scratch Project making UI.

An example:

First, declare the funccion:
definecatishungryreturnyes


Then calling it:
whenclickedforeverifcatishungry=yesthenfeedcat

Last edited by sebitommy123 (July 1, 2016 21:23:12)

alexphan
Scratcher
1000+ posts

Function that can return a value

This already exists:
define...
__init__
Scratcher
1000+ posts

Function that can return a value

alexphan wrote:

This already exists:
define...

Topic Title wrote:

Function that can return a value
alexphan
Scratcher
1000+ posts

Function that can return a value

__init__ wrote:

alexphan wrote:

This already exists:
define...

Topic Title wrote:

Function that can return a value
In that case…duplicate.

Last edited by alexphan (July 1, 2016 21:01:04)

sebitommy123
Scratcher
13 posts

Function that can return a value

No, what I refer to is first defining a funccion like so:

definecatishungryreturnyes

and then calling it like so:

whenclickedforeverifcatishungry=yesthenfeedcat

Last edited by sebitommy123 (July 1, 2016 21:21:22)

sebitommy123
Scratcher
13 posts

Function that can return a value

This would be extreamly usefull, especially for people who don't wan't to exit the Scratch Project making UI.

An example:

First, declare the funccion:
definecatishungryreturnyes


Then calling it:
whenclickedforeverifcatishungry=yesthenfeedcat

There are work arounds, but they are messy.
One is to create a variable, set it is the funccion and read it from the out side:

definecatishungrysethungrytoyes
You do this and then call the funccion from the code.

I think that this would remove all that mess of creating variables for returning.

Last edited by sebitommy123 (July 1, 2016 21:32:31)

alexphan
Scratcher
1000+ posts

Function that can return a value

It looks like you already made a topic about that here.
helloandgoodbye9
Scratcher
1000+ posts

Function that can return a value

sebitommy123 wrote:

No, what I refer to is first defining a funccion like so:

definecatishungryreturnyes

and then calling it like so:

whenclickedforeverifcatishungry=yesthenfeedcat
Yes, it is a duplicate of #1.
Also, there is a chance of it being in scratch 3.
elian_night
New Scratcher
1 post

Function that can return a value

A solution that comes to my mind would be the following:



We create a special variable named RETURN (for example) and then in every function we want to return a value we instead save that value into that variable

definecatishungry?setRETURNtoyes

And when we call the function to use the return value we make use of the RETURN variable.

whenclickedforevercatishungry?ifRETURN=yesthenfeedcat

I haven't explore this solution a lot so I don't know if it is prone to error, but even though I wanted to share it and I hope it is useful for someone.

Powered by DjangoBB