Discuss Scratch
- Zappy1333
-
Scratcher
100+ posts
Non void functions
In scratch, if you make a block, it can use arguments, but it cannot return a value.
Example:
I thin this would be a very useful feature because although there are ways to do this, it requires more blocks
Thankyou- Zappy1333
Example:
set [name] to [generate_name()]
I thin this would be a very useful feature because although there are ways to do this, it requires more blocks
Thankyou- Zappy1333
Supporters:
gregory9
RalphMath
hppavilion
Last edited by Zappy1333 (Jan. 4, 2015 11:12:15)
- DemCupcakesYo
-
Scratcher
100+ posts
Non void functions
I'm sorry, but I don't understand. Could you please explain?
- Zappy1333
-
Scratcher
100+ posts
Non void functions
I'm sorry, but I don't understand. Could you please explain?What I mean is, when you make a block, it can return a variable that can be set inside the define block
Here is a link I found about functions
It's the alternative of doing this:
define RandomBlock
set (return value::motion) to (pick random (1) to (10))
when green flag clicked
RandomBlock
set (x::motion) to (return value::motion)
because instead you could do this:
define RandomBlock
return (pick random (1) to (10))
when green flag clicked
set (x::motion) to ({RandomBlock :: looks})
Last edited by Zappy1333 (Jan. 4, 2015 11:18:57)
- stickfiregames
-
Scratcher
1000+ posts
Non void functions
This already suggests custom reporters and booleans.
define(function(arg1 :: custom-arg) (arg2 :: custom-arg) :: custom) :: custom hat
::custom cstart
...
{return (... :: grey) :: custom cap} :: custom cend cap
Last edited by stickfiregames (Dec. 7, 2014 14:09:25)
- theonlygusti
-
Scratcher
1000+ posts
Non void functions
Has already been suggested … a lot.
The ST have already pretty much implemented this anyways.
The ST have already pretty much implemented this anyways.
- lalala3
-
Scratcher
100+ posts
Non void functions
Has already been suggested … a lot.Pretty sure they haven't. Please explain.
The ST have already pretty much implemented this anyways.
Oh yeah, I'd also like to add that “has already been suggested” means that you should go over there and add your support, not that you should let the issue drop.
Last edited by lalala3 (Dec. 9, 2014 23:33:49)
- Zro716
-
Scratcher
1000+ posts
Non void functions
The ST have already pretty much implemented this anyways.citation needed
- Cyoce
-
Scratcher
500+ posts
Non void functions
Has already been suggested … a lot.How has the ST implemented this? Where? If it has, I support the ST making it a lot more accessible.
The ST have already pretty much implemented this anyways.
- MegaApuTurkUltra
-
Scratcher
1000+ posts
Non void functions
The ST have already pretty much implemented this anyways.citation needed
- RalphMath
-
New Scratcher
27 posts
Non void functions
I strongly support this and not just because it would help Scratch programming. IMHO the best argument is that value returning functions are central to both programming and more generally mathematics. Without it, Scratch is not allowing what's certainly a central idea of all algorithmic systems to be explored.
A possible way to do this might be to just have a simple “return” control block, i.e.
A possible way to do this might be to just have a simple “return” control block, i.e.
return [ ]It would both set the value of the block for the calling block and act as a “stop” for the custom block. It could also be used for a non-value returning block to terminate, the value wouldn't be needed in this case. This also has the advantage of looking like most other programming languages.
define Raise (base) to (exp)
if <<(base) < [0]> and <<(exp) mod [0]> > [0]>> then
return[] // imaginary
end
if <<(base) < [0]> and (((exp) mod [2]) = [1])> then // odd power of negative number
return(([e^ v] of (([ln v] of ([abs v] of (base))) * (exp))) * [-1])
else // even power of any number
return([e^ v] of (([ln v] of ([abs v] of (base))) * (exp)))
end
- RalphMath
-
New Scratcher
27 posts
Non void functions
To use the above:
or maybe this would be clearer:
set [value v] to (Raise [-2] to (power))
or maybe this would be clearer:
set [value v] to (call (Raise [-2] to (power)))
- hppavilion
-
Scratcher
100+ posts
Non void functions
Support
And I STILL want to know where this has been implemented, if it apparently has.
And I STILL want to know where this has been implemented, if it apparently has.
- ChocolatePi
-
Scratcher
1000+ posts
Non void functions
BumpI believe this is working on being implemented. I saw a ST member post it on something.












