Discuss Scratch

Slam-
Scratcher
100+ posts

Variable types

Do they even exist? If so, how scratch decides which variable should be boolean or integer?
SpaceExplorerPro
Scratcher
100+ posts

Variable types

Do you have a project that uses something associated with this? If so please provide a link.
Slam-
Scratcher
100+ posts

Variable types

SpaceExplorerPro wrote:

Do you have a project that uses something associated with this? If so please provide a link.
No, i dont have.
bgvikings08
Scratcher
100+ posts

Variable types

Some blocks like blocks with the orange color have a changeable integer. Blocks like ‘Costume name’ can contain names. Lists are a good way to make you own variable with things other than integers stored.
legendary34678
Scratcher
1000+ posts

Variable types

Hello! The variables that Scratch uses can store characters (so letters as well as numbers). I don't think boolean variables exist, but you can set a variable to true/false or 0/1 and then check if that variable is a certain value to mimic a boolean.
MaybeARandomFox
Scratcher
100+ posts

Variable types

Slam- wrote:

Do they even exist? If so, how scratch decides which variable should be boolean or integer?
Ok so briefly this is everything about it
Creatable variables:
  • Creatable variables are universal
    You can put it into a logical operation like this:
variable=1variable=test
But if its a prompt then
move3stepsmovevariablesteps
for numbers
and
for logical operations like:
3-0variable-1
whenIreceive
selectable prompt probably text
showvariablefoo
variable selector.
So these are the types of variables. Briefly explained in a speedrun.
CustomBlockMaker
Scratcher
25 posts

Variable types

Slam- wrote:

SpaceExplorerPro wrote:

Do you have a project that uses something associated with this? If so please provide a link.
No, i dont have.
So, there aren't really data types with scratch. But you can do
ifitem1oflistthen. . . item 1 has to be 1 or 0, 1 being true and 0 being false.
Jereb-co7
Scratcher
100+ posts

Variable types

legendary34678 wrote:

Hello! The variables that Scratch uses can store characters (so letters as well as numbers). I don't think boolean variables exist, but you can set a variable to true/false or 0/1 and then check if that variable is a certain value to mimic a boolean.
1000+ posts? HOW?
Jereb-co7
Scratcher
100+ posts

Variable types

Slam- wrote:

Do they even exist? If so, how scratch decides which variable should be boolean or integer?
Like global (for all sprites) and local (for this sprite only) variables? Yea they exist
Jereb-co7
Scratcher
100+ posts

Variable types

Slam- wrote:

Do they even exist? If so, how scratch decides which variable should be boolean or integer?
You can define a Boolean as 1=true and 0=false
awesome-llama
Scratcher
1000+ posts

Variable types

Variables/list items do have types but a lot of stuff happens out of sight.
As far as I know, they can only be strings, double floats, or booleans.
Everyone saying above that there aren't types are wrong.

Here's an example where it matters: https://scratch.mit.edu/projects/649641539/

Scratch decides the type dependent on the situation and the data involved.
For example, doing maths on a variable will automatically convert the values into numbers. For this specifically, anything that can be a number will be converted into a float, strings that cannot be interpreted as a number (say they contain letters) will be converted into a 0, and booleans will converted into 1 and 0 for true and false (very useful to know).
Something else also worth noting here is Scratch also can convert strings representing hexadecimal or binary numbers into decimal numbers. The prefix 0x or 0b needs to be included for this to happen.

For the operators that work on strings such as the join block, the values are converted into strings.

The boolean blocks also have special behaviour.
The equals block compares inputted strings as strings and numbers as numbers except if a string is composed of numbers, it will be compared as a number (something to know when dealing with cloud variables which can handle long strings of numbers whilst not actually being a numerical datatype).
The greater than and less than blocks compare numbers as you would expect but strings are compared alphabetically. With booleans, true is bigger than false.

Powered by DjangoBB