Discuss Scratch
- Discussion Forums
- » Suggestions
- » Detect if a variable is used
- KGicode314
-
Scratcher
8 posts
Detect if a variable is used
I really don't know if anyone else wrote about this already, but I couldn't find it anywhere else. I think there should be a block like:
that detects if a variable is used (specifically in a list). How it currently works using the
(variable?)
that detects if a variable is used (specifically in a list). How it currently works using the
<[list v] contains (variable) ?>block is that it will plug in the value for the variable and look for that value in the list. How I want it to work with the new block is it will detect if the variable was ever plugged into the list. For example, there is a leaderboard in a game. Your score in the game will only be added once to the list even if you have a new score. The block detects that the variable “score” was already added.
Last edited by KGicode314 (May 8, 2026 21:10:17)
- Pixalperfect
-
Scratcher
500+ posts
Detect if a variable is used
can you explain your suggestion better? because it just sounds like you could use
<[list v] contains [thing] ?> // you can replace thing with any value
Last edited by Pixalperfect (May 8, 2026 22:49:55)
- KGicode314
-
Scratcher
8 posts
Detect if a variable is used
can you explain your suggestion better? because it just sounds like you could use<[list v] contains [thing] ?> // you can replace thing with any value
@Pixalperfect,
the normal
<[list v] contains [thing] ?>would just search for “thing”, but the block I'm suggesting would basically trace the value back to the variable that was like
add (variable) to [list v]and basically say,“If this variable was ever added to this list” and not “If the value of the variable now is in the list”
Last edited by KGicode314 (May 8, 2026 23:07:36)
- Pixalperfect
-
Scratcher
500+ posts
Detect if a variable is used
(#3)ohh ok, so like acan you explain your suggestion better? because it just sounds like you could use@Pixalperfect,<[list v] contains [thing] ?> // you can replace thing with any value
the normal<[list v] contains [thing] ?>would just search for “thing”, but the block I'm suggesting would basically trace the value back to the variable that was likeadd (variable) to [list v]and basically say,“If this variable was ever added to this list” and not “If the value of the variable now is in the list”
[list v] once contained [thing] ? :: list boolean // probably needs a better nameblock?
as a workaround, you could have two lists, one that sometimes deletes entries (this would be the leaderboard that would be displayed) and then one that never gets deleted (except for maybe the start of the project). whenever you add something to the leaderboard, add it to the other list too. that way, you can check if a variable was ever apart of the leaderboard by using the other list. i hope i explained that well enough
- KGicode314
-
Scratcher
8 posts
Detect if a variable is used
@Pixalperfect,
That is a very good idea, and thank you for your help solving that problem. However, I was thinking the block could basically detect if a variable is in a list, because currently, the
Thank you, @KGicode314 (sorry my scratchblocks are broken)
That is a very good idea, and thank you for your help solving that problem. However, I was thinking the block could basically detect if a variable is in a list, because currently, the
<[list v] contains (variable) ?>block will put the current value of the variable into where the variable was placed. I was thinking the block was basically
if <[list v] contains [thing] ?> ever happened with this user then :: controlbut I can see how your solution can help.
code here :: variables
end
Thank you, @KGicode314 (sorry my scratchblocks are broken)
Last edited by KGicode314 (May 8, 2026 23:45:46)
- dinoparty0
-
Scratcher
1000+ posts
Detect if a variable is used
Is it pass by reference?
OH IS IT LIKE If the thing came from a variable specifically, what are the uses for this
OH IS IT LIKE If the thing came from a variable specifically, what are the uses for this
- KGicode314
-
Scratcher
8 posts
Detect if a variable is used
Is it pass by reference?Yes it is like that. One use I can think of is someone wants to code a leaderboard, but a player's score can only be added once or something.
OH IS IT LIKE If the thing came from a variable specifically, what are the uses for this
- abrakaidabra
-
Scratcher
500+ posts
Detect if a variable is used
Is it pass by reference?Yes it is like that. One use I can think of is someone wants to code a leaderboard, but a player's score can only be added once or something.
OH IS IT LIKE If the thing came from a variable specifically, what are the uses for this
if <not <[list v] contains [thing] ?>> then
add [thing] to [list v]
end
…would that be what you're looking for?
Last edited by abrakaidabra (Yesterday 18:09:02)
- KGicode314
-
Scratcher
8 posts
Detect if a variable is used
@abrakaidabra,
Thanks for helping, but we were looking for a solution for when you replace “thing” in your code with a variable. The reason you can't just insert the variable is the value of the variable just gets put in instead. I was looking for a way to find out if the variable was ever added to the list, even if it's value has changed.
Thanks for helping, but we were looking for a solution for when you replace “thing” in your code with a variable. The reason you can't just insert the variable is the value of the variable just gets put in instead. I was looking for a way to find out if the variable was ever added to the list, even if it's value has changed.
- dinoparty0
-
Scratcher
1000+ posts
Detect if a variable is used
It's a little confusing this suggestion; you have to read it carefully @abrakaidabra
- Discussion Forums
- » Suggestions
-
» Detect if a variable is used