Discuss Scratch

NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

Working on a new game that is similar to Word Bomb on Roblox. I wanted to randomize the letters but don't know how. Any solutions? Thanks!

Last edited by NotDisplayName (Dec. 29, 2020 08:56:20)

Vaibhs11
Scratcher
1000+ posts

How to randomize letters like how you randomize numbers?

alph contains all the letters in the alphabet.
(item (pick random (1) to (length of [alph v] :: list)) of [alph v] :: list) // instead of (length of [alph v]), you can type 26

Last edited by Vaibhs11 (Dec. 29, 2020 09:21:50)

NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

Vaibhs11 wrote:

alph contains all the letters in the alphabet.
(item (pick random (1) to (length of [alph v] :: list)) of [alph v] :: list) // instead of (length of [alph v]), you can type 26
Thanks!
NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

One more question. how do I get the sprite to say both letters? It seems to only say true.
when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
ask <(item ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list) and ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list)> and wait
end

Last edited by NotDisplayName (Dec. 29, 2020 11:53:51)

Vaibhs11
Scratcher
1000+ posts

How to randomize letters like how you randomize numbers?

NotDisplayName wrote:

One more question. how do I get the sprite to say both letters? It seems to only say true.
when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
ask <(item ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list) and ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list)> and wait
end
NO NOT LIKE THAT
(join (...) (...))
You can put those reporters in booleans but not other reporters.
It's unique and learn about Logic gates

Last edited by Vaibhs11 (Dec. 29, 2020 12:02:22)

NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

Vaibhs11 wrote:

NotDisplayName wrote:

One more question. how do I get the sprite to say both letters? It seems to only say true.
when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
ask <(item ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list) and ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list)> and wait
end
NO NOT LIKE THAT
(join (...) (...))
You can put those reporters in booleans but not other reporters.
It's unique and learn about Logic gates
Okay, it works now. Thanks again!
Vaibhs11
Scratcher
1000+ posts

How to randomize letters like how you randomize numbers?

NotDisplayName wrote:

Vaibhs11 wrote:

NotDisplayName wrote:

One more question. how do I get the sprite to say both letters? It seems to only say true.
when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
ask <(item ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list) and ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list)> and wait
end
NO NOT LIKE THAT
(join (...) (...))
You can put those reporters in booleans but not other reporters.
It's unique and learn about Logic gates
Okay, it works now. Thanks again!
Go to the link. That will help you.
NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

Vaibhs11 wrote:

NotDisplayName wrote:

Vaibhs11 wrote:

NotDisplayName wrote:

One more question. how do I get the sprite to say both letters? It seems to only say true.
when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
ask <(item ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list) and ((pick random (1) to (length of [alph] :: list)) ) of [alph v] :: list)> and wait
end
NO NOT LIKE THAT
(join (...) (...))
You can put those reporters in booleans but not other reporters.
It's unique and learn about Logic gates
Okay, it works now. Thanks again!
Go to the link. That will help you.
Sure thing. Thanks again!
NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

One more question before I really stop asking.
How do you make it where a word contains the 2 letters presented on the screen are valid?
For example, the two letters shown are sh.
I put pushed in the answer section.
Then, instead of “Amazing!”, it instead says “You lost a life.” which is the win-lose greeting.
How do I do it? Thanks!
awesome-llama
Scratcher
1000+ posts

How to randomize letters like how you randomize numbers?

NotDisplayName wrote:

One more question before I really stop asking.
How do you make it where a word contains the 2 letters presented on the screen are valid?
For example, the two letters shown are sh.
I put pushed in the answer section.
Then, instead of “Amazing!”, it instead says “You lost a life.” which is the win-lose greeting.
How do I do it? Thanks!
Not sure if I am understanding your question right, but you are asking how to check whether the two letters are contained in the answer, right?

If so, you will need to instead store the random letters in a variable so you can use the same letters multiple times.

See this example:

when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
set [letters v] to (join (item (pick random (1) to (length of [alph v]::list)) of [list v] :: list) (item (pick random (1) to (length of [alph v]::list)) of [list v] :: list))
ask (letters) and wait
if <(answer) contains (letters)?::operators> then
... // the two letters were in the answer
else
... // the two letters were not in the answer
end

Note that this assumes you want to be detecting the two letters together, e.g. the sh in pushed and not the individual letters s and h in a word like hats.
NotDisplayName
Scratcher
20 posts

How to randomize letters like how you randomize numbers?

awesome-llama wrote:

NotDisplayName wrote:

One more question before I really stop asking.
How do you make it where a word contains the 2 letters presented on the screen are valid?
For example, the two letters shown are sh.
I put pushed in the answer section.
Then, instead of “Amazing!”, it instead says “You lost a life.” which is the win-lose greeting.
How do I do it? Thanks!
Not sure if I am understanding your question right, but you are asking how to check whether the two letters are contained in the answer, right?

If so, you will need to instead store the random letters in a variable so you can use the same letters multiple times.

See this example:

when I receive [WordBombLetter v]
forever
say [Find a word that has the letters...] for (2) secs
set [letters v] to (join (item (pick random (1) to (length of [alph v]::list)) of [list v] :: list) (item (pick random (1) to (length of [alph v]::list)) of [list v] :: list))
ask (letters) and wait
if <(answer) contains (letters)?::operators> then
... // the two letters were in the answer
else
... // the two letters were not in the answer
end

Note that this assumes you want to be detecting the two letters together, e.g. the sh in pushed and not the individual letters s and h in a word like hats.
Yep, this works! Thank you! Might also look at your game because it looks epic.

Powered by DjangoBB