Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » detecting if this is the first time this player has went on a project?
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
Is it possible to detect the first time a player went on a project?
Ex. Someone with the username somerandomguy plays on my project and this is his first time, and gets some bonus because it is his first time. And then when he presses the flag again, the game would know it isn't his first time and wouldn't give a bonus boost.
If it is possible, how do you do it?
Ex. Someone with the username somerandomguy plays on my project and this is his first time, and gets some bonus because it is his first time. And then when he presses the flag again, the game would know it isn't his first time and wouldn't give a bonus boost.
If it is possible, how do you do it?
- TheUltimatum
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
You would have to use some sort of cloud list engine to save the persons username to a list if the list doesn't already have their name in it. If the list has their name in it then the have already visited the project. You could probably use @leafinos cloud list engine which is one of the easier to use cloud lists.
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
You would have to use some sort of cloud list engine to save the persons username to a list if the list doesn't already have their name in it. If the list has their name in it then the have already visited the project. You could probably use @leafinos cloud list engine which is one of the easier to use cloud lists.Ok.. I went to the project, but I can see these ‘'Hacked Custom Blocks’'. And how can you make these, because when I go and look at the More Blocks section in this project, and press Edit on the hacked custom block, I see no thing that could make those things on the custom blocks..
Last edited by ninja78912 (June 26, 2015 14:34:00)
- deck26
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
You don't need hacked custom blocks to make a ‘cloud list’. Custom blocks can be useful but ‘hacked’ suggests they're doing something more than can be done just using Scratch normally. I've only had a quick look but I think @Leafino is just using normal custom blocks. You can either just remix their project or copy scripts or sprites via the backpack if you want to use their code although I'd always prefer to understand the code in my projects.
My cloud list project is here https://scratch.mit.edu/projects/22828152/ - not sure if it's any easier to understand.
My cloud list project is here https://scratch.mit.edu/projects/22828152/ - not sure if it's any easier to understand.
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
You don't need hacked custom blocks to make a ‘cloud list’. Custom blocks can be useful but ‘hacked’ suggests they're doing something more than can be done just using Scratch normally. I've only had a quick look but I think @Leafino is just using normal custom blocks. You can either just remix their project or copy scripts or sprites via the backpack if you want to use their code although I'd always prefer to understand the code in my projects.Uh. Leafino's engine does use hacked custom blocks, if you looked at the custom blocks section you would see it. And I see yours with a ton of variables. I don't want to use a lot of variables because the project I'm adding this feature in, Already has a ton of variables as well
My cloud list project is here https://scratch.mit.edu/projects/22828152/ - not sure if it's any easier to understand.
- deck26
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
Most projects that do this are going to have their own variables! If you don't want to add more variables to your project you need to work out how to create your own version with the variables you have or with minimal additions. If you can understand the code that shouldn't be a problem.
My version would actually suit your needs quite well since you could use it without the decode at all - only required if you actually want to display the list of names which it doesn't sound like you need. My finduser block looks for the encoded username in the cloud variable without decoding it and adding a new username to the list doesn't require the list to be decoded either. The finduser block can search through the variable quickly as each username has its encoded length recorded so if the next name is the wrong length it can skip forward to the next name in the list and check the length. So it only looks for a match when the encoded name is the right length.
You call, obviously, but the main thing is you CAN do this without hacked blocks, you just need to understand how encoding and decoding work.
My version would actually suit your needs quite well since you could use it without the decode at all - only required if you actually want to display the list of names which it doesn't sound like you need. My finduser block looks for the encoded username in the cloud variable without decoding it and adding a new username to the list doesn't require the list to be decoded either. The finduser block can search through the variable quickly as each username has its encoded length recorded so if the next name is the wrong length it can skip forward to the next name in the list and check the length. So it only looks for a match when the encoded name is the right length.
You call, obviously, but the main thing is you CAN do this without hacked blocks, you just need to understand how encoding and decoding work.
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
Most projects that do this are going to have their own variables! If you don't want to add more variables to your project you need to work out how to create your own version with the variables you have or with minimal additions. If you can understand the code that shouldn't be a problem.I'm still very confused because I understand almost nothing about your engine
My version would actually suit your needs quite well since you could use it without the decode at all - only required if you actually want to display the list of names which it doesn't sound like you need. My finduser block looks for the encoded username in the cloud variable without decoding it and adding a new username to the list doesn't require the list to be decoded either. The finduser block can search through the variable quickly as each username has its encoded length recorded so if the next name is the wrong length it can skip forward to the next name in the list and check the length. So it only looks for a match when the encoded name is the right length.
You call, obviously, but the main thing is you CAN do this without hacked blocks, you just need to understand how encoding and decoding work.

Can you explain what the blocks do?
- deck26
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
Have you looked at the comments in the stage?
The custom block ‘encode_str’ encodes a string of text, returning the result in variable tempstr The length of this (as two digits) is added to the front of this so my cloud variable is a collection of blocks like this (length, encode name, length, encoded name etc).
Encode_str calls the custom block ‘encode-char’ to encode a single character - so each character in the string to be encoded is converted to a two digit code (returned as enc-char. It uses the trick where costume names are case dependent so if you try to switch costume to an upper case letter it does work but if it is a lower case letter it doesn't change the costume. I have a separate project that uses just two costumes to detect upper or lower case if of interest.
Decode-all decodes a cloud variable and splits it into a list which in this case is a list of usernames. But my point earlier was you don't need to do this as you can just search the cloud variable for the encoded version of the username.
Find-user is the custom block which searches for an encoded username in the cloud variable. Since the lengths are part of the data we can use that to skip through the list quickly. So if the username is length 6 and the next name in the cloud variable has 7 characters we can ignore it and move on. When we do find a name of length 6 we check the encoded version of the name against the next few characters. If find-user returns a positive value for variable found the encoded username was in the cloud variable.
The user index just shows where in the list the username appears. That's not relevant for you but is useful when one wants to store other data for a user in a separate list.
The custom block ‘encode_str’ encodes a string of text, returning the result in variable tempstr The length of this (as two digits) is added to the front of this so my cloud variable is a collection of blocks like this (length, encode name, length, encoded name etc).
Encode_str calls the custom block ‘encode-char’ to encode a single character - so each character in the string to be encoded is converted to a two digit code (returned as enc-char. It uses the trick where costume names are case dependent so if you try to switch costume to an upper case letter it does work but if it is a lower case letter it doesn't change the costume. I have a separate project that uses just two costumes to detect upper or lower case if of interest.
Decode-all decodes a cloud variable and splits it into a list which in this case is a list of usernames. But my point earlier was you don't need to do this as you can just search the cloud variable for the encoded version of the username.
Find-user is the custom block which searches for an encoded username in the cloud variable. Since the lengths are part of the data we can use that to skip through the list quickly. So if the username is length 6 and the next name in the cloud variable has 7 characters we can ignore it and move on. When we do find a name of length 6 we check the encoded version of the name against the next few characters. If find-user returns a positive value for variable found the encoded username was in the cloud variable.
The user index just shows where in the list the username appears. That's not relevant for you but is useful when one wants to store other data for a user in a separate list.
- Superthunder5000
-
Scratcher
73 posts
detecting if this is the first time this player has went on a project?
Easy
when green flag clicked
if <[Any list v] contains [(username) ]> then
Whatever you wanna do
else <> then
add (username) to [ Any list v]
end
Last edited by Superthunder5000 (June 26, 2015 21:23:45)
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
EasyAnd how exactly will this be a cloud list.when green flag clicked
if <[Any list v] contains [(username) ]> then
Whatever you wanna do
else <> then
add (username) to [ Any list v]
end
Last edited by ninja78912 (June 26, 2015 21:30:49)
- purplebook163
-
Scratcher
500+ posts
detecting if this is the first time this player has went on a project?
A very simple way you could do this would be by having a cloud variable. Your script would look something like this:
If the value of the “☁ Played before?” variable equals 1, then the player doesn't get the reward, and the game starts.
If you have any questions, please ask.
when green flag clickedWhen the green flag is clicked the “☁ Played before?” variable is set to whatever it was last time the player played. If the player hasn't played before, it is automatically set to 0. So, the script then checks to see what the value of the “☁ Played before?” variable is. If it is a 0, then the player has never played before and gets the reward. Then the variabke is set to 1, which indicates that the project has been played before and the next time the project is played, the script will recognize it.
set [☁ Played before? v] to [ ☁ Played before? ]
if <(☁ Played before?) = [ 0 ]> then
add bonus for being first time
set [☁ Played before? v] to [ 1 ]
end
if <(☁ Played before?) = [ 1 ]> then
don't add bonus because they've played before
end
If the value of the “☁ Played before?” variable equals 1, then the player doesn't get the reward, and the game starts.
If you have any questions, please ask.

- Vetpetmon
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
Odd… this really isn't griffpatch level, but I might be able to fix your problem, but I don't have time…
I might come back tomorrow to help you, but it's past my bedtime…
I might come back tomorrow to help you, but it's past my bedtime…
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
A very simple way you could do this would be by having a cloud variable. Your script would look something like this:Um? Wouldn't there be a problem?? If one player that hasn't been in this project before and gets the reward, then the next person who also never had came won't get the reward because it's set to one already?when green flag clickedWhen the green flag is clicked the “☁ Played before?” variable is set to whatever it was last time the player played. If the player hasn't played before, it is automatically set to 0. So, the script then checks to see what the value of the “☁ Played before?” variable is. If it is a 0, then the player has never played before and gets the reward. Then the variabke is set to 1, which indicates that the project has been played before and the next time the project is played, the script will recognize it.
set [☁ Played before? v] to [ ☁ Played before? ]
if <(☁ Played before?) = [ 0 ]> then
add bonus for being first time
set [☁ Played before? v] to [ 1 ]
end
if <(☁ Played before?) = [ 1 ]> then
don't add bonus because they've played before
end
If the value of the “☁ Played before?” variable equals 1, then the player doesn't get the reward, and the game starts.
If you have any questions, please ask.
This would be so much easier if, there was not that “ONLY 10 CLOUD VARIABLES per Project”, or you can only put numbers into the cloud variables.
And I wish they also added Cloud Lists! If cloud lists were added, it would be so much easier. And removed Cloud Variable limits!
Last edited by ninja78912 (June 27, 2015 14:55:16)
- deck26
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
A very simple way you could do this would be by having a cloud variable. Your script would look something like this:This appears to be based on a misunderstanding of how cloud variables work. If you have a cloud variable as described all players see the latest value of the cloud variable. So as soon as one person has played it will assume every future player has already run the project.when green flag clickedWhen the green flag is clicked the “☁ Played before?” variable is set to whatever it was last time the player played. If the player hasn't played before, it is automatically set to 0. So, the script then checks to see what the value of the “☁ Played before?” variable is. If it is a 0, then the player has never played before and gets the reward. Then the variabke is set to 1, which indicates that the project has been played before and the next time the project is played, the script will recognize it.
set [☁ Played before? v] to [ ☁ Played before? ]
if <(☁ Played before?) = [ 0 ]> then
add bonus for being first time
set [☁ Played before? v] to [ 1 ]
end
if <(☁ Played before?) = [ 1 ]> then
don't add bonus because they've played before
end
If the value of the “☁ Played before?” variable equals 1, then the player doesn't get the reward, and the game starts.
If you have any questions, please ask.
- ninja78912
-
Scratcher
7 posts
detecting if this is the first time this player has went on a project?
.. That's literally what I just said..A very simple way you could do this would be by having a cloud variable. Your script would look something like this:This appears to be based on a misunderstanding of how cloud variables work. If you have a cloud variable as described all players see the latest value of the cloud variable. So as soon as one person has played it will assume every future player has already run the project.when green flag clickedWhen the green flag is clicked the “☁ Played before?” variable is set to whatever it was last time the player played. If the player hasn't played before, it is automatically set to 0. So, the script then checks to see what the value of the “☁ Played before?” variable is. If it is a 0, then the player has never played before and gets the reward. Then the variabke is set to 1, which indicates that the project has been played before and the next time the project is played, the script will recognize it.
set [☁ Played before? v] to [ ☁ Played before? ]
if <(☁ Played before?) = [ 0 ]> then
add bonus for being first time
set [☁ Played before? v] to [ 1 ]
end
if <(☁ Played before?) = [ 1 ]> then
don't add bonus because they've played before
end
If the value of the “☁ Played before?” variable equals 1, then the player doesn't get the reward, and the game starts.
If you have any questions, please ask.
- TheUltimatum
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
All the op would have to do is drag leafinos engine into their backpack and drag it back into the project they would like to use it in.
Last edited by TheUltimatum (June 29, 2015 19:20:18)
- purplebook163
-
Scratcher
500+ posts
detecting if this is the first time this player has went on a project?
Okay, thanks for correcting me guys!
- A-Boy123
-
Scratcher
5 posts
detecting if this is the first time this player has went on a project?
when green flag clicked
if <[ v] contains [Username] ?> then
broadcast [ They have been here]
else
broadcast [ They have not been here]
add [Username] to [list v]
Last edited by A-Boy123 (March 16, 2021 17:26:48)
- Nezon
-
Scratcher
1000+ posts
detecting if this is the first time this player has went on a project?
This topic is dead. Please don't post here, which is Necropostingwhen green flag clicked
if <[ v] contains [Username] ?> then
broadcast [ They have been here]
else
broadcast [ They have not been here]
add [Username] to [list v]
Also, lists are not cloud
- emots
-
Scratcher
1 post
detecting if this is the first time this player has went on a project?
A-Boy123
Why does this not work???
WHY DOES THIS NOT WORK!!!???
I tried this in my game but it did not work
Why does this not work???
when green flag clicked
if <[ v] contains [Username] ?> then
broadcast [ They have been here]
else
broadcast [ They have not been here]
add [Username] to [list v]
WHY DOES THIS NOT WORK!!!???
I tried this in my game but it did not work
Last edited by emots (Dec. 12, 2021 21:37:08)
- Discussion Forums
- » Help with Scripts
-
» detecting if this is the first time this player has went on a project?








