Discuss Scratch

nubynub
Scratcher
60 posts

How to make something that says (variable)=1-100

So basically I just want something that can just include a range of numbers. NOT A PICK RANDOM. Can I please have some help?
GalakC
Scratcher
500+ posts

How to make something that says (variable)=1-100

what do you mean by a range of numbers? you can just set the variable to “1-100”.
nubynub
Scratcher
60 posts

How to make something that says (variable)=1-100

I don’t know how I can’t find any operators that do so.
musicROCKS013
Scratcher
1000+ posts

How to make something that says (variable)=1-100

Like this?

define Start at (starting) and go until (end)
set [Start v] to [starting]
repeat ((end) - (starting))
add [Start] to [numbers v]
change [Start v] by (1)
end
nubynub
Scratcher
60 posts

How to make something that says (variable)=1-100

No i mean something like this
(pick random () to (10))

But without the pick random
musicROCKS013
Scratcher
1000+ posts

How to make something that says (variable)=1-100

nubynub wrote:

No i mean something like this
(pick random () to (10))

But without the pick random
Like do the code that I used, and then use this block:

<[ v] contains [thing] ?>
RT_Borg
Scratcher
1000+ posts

How to make something that says (variable)=1-100

nubynub wrote:

So basically I just want something that can just include a range of numbers. NOT A PICK RANDOM. Can I please have some help?

Hi nubynub,

We're having trouble helping you because it's not clear what you're trying to do when you say “something that can just include a range of numbers”.

GalakC guessed you might mean a variable that literally says what a range is. The text “1-100”.

musicROCKS013 guessed you might want a list with 100 items, the numbers 1-100.

My guess is that you want to keep getting numbers, and the first time you ask, you want the value 1, the second time you want the value 2 … the hundredth time you want the number 100, and the 101th time you ask, you want the number 1 again.

If that's what you want, you can use a custom block to do something similar:

(counter)  // make the variable

define advance-counter
change [counter v] by (1)
if <(counter) > [100]> then
set [counter v] to [1]
end

Note, if you have code that would normally “set” counter to a number that might be out of your range (like to 1000) you would also want to write a custom block set-in-range like:

define set-counter (value)
set [counter v] to (value)
if <(counter) > [100]> then
set [counter v] to [100]
if <(counter) < [1]> then
set [counter v] to [1]
end

To use it, you would:

set-counter [1]::custom
now (counter) has the value 1::grey
advance-counter::custom
now (counter) has the value 2::grey
repeat (98)
advance-counter::custom
end
now (counter) has the value 100::grey
advance-counter::custom
now (counter) has the value 1::grey
set-counter [1000]::custom
now (counter) has the value 100::grey
set-counter [-50]::custom
now (counter) has the value 1::grey

As long as your code never uses the standard block “change counter by” or “set counter to”, and always use the advance-counter and set-counter custom blocks instead, the rest of your code can use “counter” like any other variable but it will always be in your 1-100 range.

This could also get fancier if needed (for example, the advance-counter block could take an input instead of always changing by 1) but this gives the basic idea.

I hope this helps, or if not, maybe you can describe what this will be used for and/or how you want to use it.

– RT_Borg
nubynub
Scratcher
60 posts

How to make something that says (variable)=1-100

Okay thank you so much. That was very helpful.
Roboproffa
Scratcher
10 posts

How to make something that says (variable)=1-100

Do you mean this:

when green flag clicked
set [last value] to [0]
set [value] to (last value)
if <not (value) = (last value)
say [join [variable = ] (value)]
set [last value] to (value)

Last edited by Roboproffa (May 21, 2022 06:10:18)

Frost2151
New Scratcher
0 posts

How to make something that says (variable)=1-100

Wait how do you do it for direction
Zhergul
Scratcher
5 posts

How to make something that says (variable)=1-100

hi

Last edited by Zhergul (Aug. 27, 2023 11:29:21)

Zhergul
Scratcher
5 posts

How to make something that says (variable)=1-100

when green flag clicked
Zhergul
Scratcher
5 posts

How to make something that says (variable)=1-100

when green flag clicked
forever
if <(foo) = []> then
show
end
end

I need to put the range of numbers, 15-30, in the
if <(foo) = []> then

end
block

Last edited by Zhergul (Aug. 27, 2023 11:31:10)

josueart
Scratcher
500+ posts

How to make something that says (variable)=1-100

Zhergul wrote:

snip
Please don't necropost. Create a new topic instead. Thanks.
Tristancodin
Scratcher
36 posts

How to make something that says (variable)=1-100

when this sprite clicked
next costume
when [right] key pressed
next costume
Tristancodin
Scratcher
36 posts

How to make something that says (variable)=1-100

when [right] key pressed
point towards [Sprite1]
Tristancodin
Scratcher
36 posts

How to make something that says (variable)=1-100

when green flag clicked
forever
next costume

Last edited by Tristancodin (Oct. 11, 2023 18:40:16)

existentialcrisises
Scratcher
100+ posts

How to make something that says (variable)=1-100

Please don't go off topic. This topic is essentially solved. If you wanted to test out how the scratchblocks work in the forums, there is a topic just for that, here: https://scratch.mit.edu/discuss/topic/706823/
bird_kao_kao
Scratcher
1 post

How to make something that says (variable)=1-100

failure
PuffyFrog1
Scratcher
7 posts

How to make something that says (variable)=1-100

hay i never used the discuss thing but um how do i make a “if variable” more example “if score 200 then” well the rest doesn't matter so yeah i need just a little help with this

Powered by DjangoBB