Hello everybody, I am new to scratch/byob, and I've been playing around with the program for a little while now. I'm trying to create a guessing game which involves two players. The first player keys in a word, and the second player has to guess the word. I understand how to create the variable for the secret word, but the issue I have is, when the second player guesses incorrectly, the computer must tell the player how many letters he guessed correctly (not necessarily the exact location of which letter was guessed correctly, just the total number).
I'm not sure how I would, in a sense, separate the word into individual letters.
Can anybody help me?
Thanks.
Offline
Probably with a script like this:
set [counter v] to (1) repeat (length of (string)) //replace the (string) variable with whatever yours is called. add (letter (counter) of (string)) to [characters v] change [counter v] by (1) endDo you know how to use lists? If not, check out Lists on the Scratch Wiki.
Last edited by scimonster (2012-01-29 03:08:16)
Offline
Try this:
when gf clicked ask [Player 1: type in a word and don't let player 2 see!] and wait set [secret word v] to (answer) set [count v] to [0] repeat (length of (secret word)) change [count v] by (1) add (letter (count) of (secret word)) to [secret word list v] end repeat (allowed guesses) ask [Player 2: Try to guess player 1's word] and wait set [guess v] to (answer) if <(guess) = (secret word)> say [Well done! You guessed the word!] for (2) secs stop script end set [count v] to [0] set [correct letters v] to [0] repeat (length of (guess)) change [count v] by (1) if <[secret word list v] contains (letter (count) of (guess))> change [correct letters v] by (1) end end say (join (join [You got ](correct letters))[ right!]) for (2) secs end say (join (join [Too bad! You have run out of guesses. The word was ](secret word))[.])
Last edited by joefarebrother (2012-01-29 05:15:33)
Offline
You don't have to use lists for that. I would do it like this.
set [correct letters v] to (0) set [current letter v] to (1) repeat (length of (original word)) if <(letter (current letter) of (guess)) = (letter (current letter) of (original word))> change [correct letters v] by (1) end change [current letter v] by (1) end

Offline
aryabtsev wrote:
You don't have to use lists for that. I would do it like this.
set [correct letters v] to (0) set [current letter v] to (1) repeat (length of (original word)) if <(letter (current letter) of (guess)) = (letter (current letter) of (original word))> change [correct letters v] by (1) end change [current letter v] by (1) end
Don't people read the date? It expired 2 months ago.
Offline
Am going to try that...... but going to edit some of the scripts.
Offline