This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-01-29 02:37:48

pdubu
New Scratcher
Registered: 2012-01-29
Posts: 19

Guessing a secret word script!

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

 

#2 2012-01-29 03:07:17

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Guessing a secret word script!

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)
end
Do you know how to use lists? If not, check out Lists on the Scratch Wikismile

Last edited by scimonster (2012-01-29 03:08:16)

Offline

 

#3 2012-01-29 05:13:26

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Guessing a secret word script!

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)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#4 2012-04-03 19:22:31

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: Guessing a secret word script!

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


http://i.imgur.com/NX7AO.jpg

Offline

 

#5 2012-04-03 20:03:03

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: Guessing a secret word script!

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.


Get ready for domination of:  tongue

Offline

 

#6 2012-05-28 19:35:44

ScratchToonie
New Scratcher
Registered: 2012-05-13
Posts: 12

Re: Guessing a secret word script!

Am going to try that...... but going to edit some of the scripts.

Offline

 

Board footer