Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Project.json variable creation.
- -EmeraldThunder-
-
Scratcher
1000+ posts
Project.json variable creation.
I've been trying to implement variables into a side project of mine and have been trying to get these appended into the json on compile.
I have found the particular object which holds variables in the json.
How can I generate the hash that is the key of the variable array?
Edit:
Looks like the key is just a ranodm id. It would still be nice to generate one without a big long list of characters.
I have found the particular object which holds variables in the json.
"variables":{"P/T!j8/7Eg]MOO:-Tw/q":["test",0]}
Edit:
Looks like the key is just a ranodm id. It would still be nice to generate one without a big long list of characters.
Last edited by -EmeraldThunder- (Nov. 6, 2021 12:15:04)
- Chiroyce
-
Scratcher
1000+ posts
Project.json variable creation.
that is the key of the variable array?Which would be
“variables”:{"P/T!j8/7Eg]MOO:-Tw/q":}the underlined, right?
then —
# Assuming that you're using Python import hashlib hash = 'P/T!j8/7Eg]MOO:-Tw/q'.encode() # to convert a string to bytes hash = hashlib.sha256(hash).hexdigest() print(hash)
Is this what you want?
Last edited by Chiroyce (Nov. 6, 2021 11:27:10)
- -EmeraldThunder-
-
Scratcher
1000+ posts
Project.json variable creation.
Is this what you want?No I want to be able to just generate a random valid hash.
- Chiroyce
-
Scratcher
1000+ posts
Project.json variable creation.
random valid hasherm … is it this?

or am I missing something?
- -EmeraldThunder-
-
Scratcher
1000+ posts
Project.json variable creation.
Sorry that's not what I meant.random valid hashor am I missing something?
Is there a library oir something that will let me generate a 20 character hash similar to the one under targets.varaibles. I really don't want to have to create a list of file will all the characters in it.
Last edited by -EmeraldThunder- (Nov. 6, 2021 12:10:15)
- Chiroyce
-
Scratcher
1000+ posts
Project.json variable creation.
Is there a library oir something that will let me generate a 20 character hash similar to the one under targets.varaibles. I really don't want to have to create a list of file will all the characters in it.hmm … since scratch is written in JavaScript, it may not be very easy. Why don't you go around Scratch's GitHub code to see how it generates the hash
Last edited by Chiroyce (Nov. 6, 2021 12:21:46)
- -EmeraldThunder-
-
Scratcher
1000+ posts
Project.json variable creation.
Wrote this with a little bit of help from co-pilot to condense the for loop in line 6.
Reported to be closed as resolved.
import random import string import base64 def rand_b64(length): data = ''.join(random.choice(string.ascii_letters) for _ in range(length)).encode('utf-8') return str(base64.b64encode(data), "utf-8") print(rand_b64(15))
Last edited by -EmeraldThunder- (Nov. 6, 2021 12:35:39)
- Maximouse
-
Scratcher
1000+ posts
Project.json variable creation.
Wrote this with a little bit of help from co-pilot to condense the for loop in line 6.There is no reason to encode letters as base64 – it just makes the string longer.Reported to be closed as resolved.import random import string import base64 def rand_b64(length): data = ''.join(random.choice(string.ascii_letters) for _ in range(length)).encode('utf-8') return str(base64.b64encode(data), "utf-8") print(rand_b64(15))
- Discussion Forums
- » Advanced Topics
-
» Project.json variable creation.