Discuss Scratch

Industrialized
Scratcher
20 posts

Custom block definitions cant change input variables

I am making a game right now that might use a lot of statuses (true or false thingies), so i decided to make a block that can change it. What I have right now is:

define “switch <status> to other status”
if <status> = 0 then
set <other variable> to 1

It seems as tho the set variable block cant change custom block inputs.

Is there any way to do this?

Last edited by Industrialized (March 27, 2025 23:40:01)

NoUsername-King
Scratcher
100+ posts

Custom block definitions cant change input variables

No, unlike other programing languages, the custom block inputs aren't changeable. A possible workaround would be to set a variable to the custom block input and then change that.
geramihasfood
Scratcher
100+ posts

Custom block definitions cant change input variables

Industrialized wrote:

I am making a game right now that might use a lot of statuses (true or false thingies), so i decided to make a block that can change it. What I have right now is:

define “switch <status> to other status”
if <status> = 0 then
set <other variable> to 1

It seems as tho the set variable block cant change custom block inputs.

Is there any way to do this?
Are you saying that the set variable block meaning this:
set [... v] to [...]
can't change custom block inputs, meaning this:
(input :: custom)
?

If that's the case, then of course it can't, I don't really know a way to change the custom block inputs other than by calling the block and setting an input, like this:
smooth glide to x: [200] and y: [0] :: custom
This is an example.

I hope this answered your question.

Last edited by geramihasfood (March 28, 2025 00:11:27)

Industrialized
Scratcher
20 posts

Custom block definitions cant change input variables

gah dayum they need to add this (and also right click and middle click and scroll detection)
102acrimea
Scratcher
100+ posts

Custom block definitions cant change input variables

Industrialized wrote:

gah dayum they need to add this (and also right click and middle click and scroll detection)
Scroll detection is possible but right click and middle click are also possible with certain addons (local addons).

Scroll detection is possible with a when key up arrow or key down arrow event reciever (can't be a green flag loop) that checks if the key up arrow or down arrow is not pressed, then scrolls if so. I can show a demo project if you want.
EpicGhoul993
Scratcher
1000+ posts

Custom block definitions cant change input variables

Industrialized wrote:

Is there any way to do this?
The only way is to put the initial values into variables, and change those variables when you need to.
deck26
Scratcher
1000+ posts

Custom block definitions cant change input variables

The standard method is to use a return variable - ie a global variable called (eg) return. You can then set the correct variable to the return value after calling the custom block.

In many languages you can either pass only the value of the parameter in a subroutine call or pass the variable by reference. In the latter case you CAN change the variable in the subroutine but not in the first case. Which to use can often be decided by the programmer according to their needs. In Scratch you can only pass values so the custom block knows nothing about the variable, only the value at the time the custom block was called.

There are various areas where Scratch is less suitable for coding than more serious languages but it is aimed at being an introductory language and keeping things simple is part of that. Most of my programming in the past required file input and output for example and Scratch just doesn't do that. String handling (eg substring functions) and binary functions like and/or/xor are also just completely missing. I could go on!

Powered by DjangoBB