Page 216 - Learn To Program With Scratch
P. 216

The Remove procedure, which lets us avoid adding the same letter to
                         our scrambled word twice, is shown in Figure 8-12. It removes a character
                         from strIn at the position you specify with the charPos parameter.






                                                                     

                                                                     

                                                                     



                                                                     

                                                                     

                         Figure 8-12: The Remove procedure

                             This procedure uses another temporary string, named str2, to build
                         the new string we want to create. It starts by emptying str2 and setting a
                         loop counter, n, to 1 to access the first character of strIn u. The procedure
                         then starts a repeat loop to assemble the output string v. If we don’t want
                         to delete the current character, we append it to str2 w. The loop counter is
                         then incremented to access the next letter of strIn x. When the procedure
                         finishes, strIn is set to the new word (str2) y.
                             Now we are ready to explore the main script of the game, shown in
                         Figure 8-13.




                                                            
                                                            
                                                            
                                                            
                                                            




                                                            





                         Figure 8-13: The main script of the Unscramble game




           194   Chapter 8
                                           www.it-ebooks.info
   211   212   213   214   215   216   217   218   219   220   221