Discuss Scratch

StarGjikolli
Scratcher
55 posts

How can I make one time codes

I’m trying to make a code works once and never again. Can someone help me?
when green flag clicked
say [exactly help me]
deck26
Scratcher
1000+ posts

How can I make one time codes

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.
StarGjikolli
Scratcher
55 posts

How can I make one time codes

deck26 wrote:

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.



It’s for this: https://scratch.mit.edu/projects/1095167775
deck26
Scratcher
1000+ posts

How can I make one time codes

StarGjikolli wrote:

deck26 wrote:

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.



It’s for this: https://scratch.mit.edu/projects/1095167775
Doesn't tell me anything!
StarGjikolli
Scratcher
55 posts

How can I make one time codes

deck26 wrote:

StarGjikolli wrote:

deck26 wrote:

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.



It’s for this: https://scratch.mit.edu/projects/1095167775
Doesn't tell me anything!
click add points and type 1234 over and over
StarGjikolli
Scratcher
55 posts

How can I make one time codes

deck26 wrote:

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.


You know what? Once for one user.
jmb1293634
Scratcher
1000+ posts

How can I make one time codes

this might work depending on exactly what you want:
when green flag clicked
wait until <whatever your condition is>
do whatever you want it to
deck26
Scratcher
1000+ posts

How can I make one time codes

StarGjikolli wrote:

deck26 wrote:

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.


You know what? Once for one user.
You asked me via my profile to help here but as far as I can see I've already answered the question. You need to store the encoded usernames of those who have used the code and, if necessary, a reference to the codes they've used. There's info in the Wiki about encoding usernames but cloud variables are generally a bit unreliable in my opinion - I believe they're down at the moment.

Cloud variables are the same for all users so you can't just store the information that a code has been used - you need to store the information that it has been used by that user. Cloud variables only hold numerical digits so you have to encode the username.
RicDiamond1477
Scratcher
100+ posts

How can I make one time codes

StarGjikolli wrote:

deck26 wrote:

You mean only once for one user or only once across all users? Why do you want to do this? What are you actually trying to achieve?

The only way I can see of doing this is to use cloud variables. If the use of a code is once per users you've have to encode the usernames and somehow record the codes they's used - you could use a shorter reference rather than the actual code(s) to save space. If a code is only once for all users you could just record which codes have been used without worrying about usernames.


You know what? Once for one user.
You can do this:
when green flag clicked
forever
if <[Whatever you are doing] = [1234]> then
Do what you want
stop [This Script v]

end
end

Last edited by RicDiamond1477 (Jan. 23, 2025 13:33:32)

deck26
Scratcher
1000+ posts

How can I make one time codes

RicDiamond1477 wrote:

You can do this:
when green flag clicked
forever
if <[Whatever you are doing] = [1234]> then
Do what you want
stop [This Script v]

end
end

I don't think you understand the question. If you don't use the cloud to save something the user can reload the project and there is nothing to prevent them using the code again.
KamiraDuck
Scratcher
13 posts

How can I make one time codes


when green flag clicked
forever
if <[variable] = [0]> then


say [Not seen yet] for (2) secs
set [variable] to [1]
else
say [Already seen] for (2) secs
end
end

When somebody exits the game, the variables are saved.
abrakaidabra
Scratcher
500+ posts

How can I make one time codes

KamiraDuck wrote:

when green flag clicked
forever
if <[variable] = [0]> then


say [Not seen yet] for (2) secs
set [variable] to [1]
else
say [Already seen] for (2) secs
end
end

When somebody exits the game, the variables are saved.
Regular variables are reset when someone exits the game
abrakaidabra
Scratcher
500+ posts

How can I make one time codes

You would have to use cloud variables to save a user’s username using a cloud list. However, cloud variables are currently broken in scratch and do not save values after a player leaves the game. The other option would be to use python to connect to a different server used something like scratchclient or scratchattach, as used here.
KamiraDuck
Scratcher
13 posts

How can I make one time codes

oh my bad, I tried making one on one of my games and it worked so bit confusing lol.
abrakaidabra
Scratcher
500+ posts

How can I make one time codes

KamiraDuck wrote:

oh my bad, I tried making one on one of my games and it worked so bit confusing lol.
If you are the creator and you’re running the game in the editor, then the variable would save.
Kpate123
Scratcher
100+ posts

How can I make one time codes

Set a variable to 0 then do this
. . .
if <(foo) = [0]> then
set [foo v] to [1]
. . .
end
abrakaidabra
Scratcher
500+ posts

How can I make one time codes

Kpate123 wrote:

Set a variable to 0 then do this
. . .
if <(foo) = [0]> then
set [foo v] to [1]
. . .
end
But then when you reload the project you could use the code again

Powered by DjangoBB