I've been working on a project where it asks for input, you type something, and it moves a spirte along stamping each letter out to make the words you put in, but stupidly scratch makes costume changing to number, not names. so it gets item 1 of list "sent" (because sentence was taken by a variable) and changes costume to item one of sent. but wait a minute, item 1 is H! I can't change to H because H isn't a number! is there a way round this without stupid amounts of coding?
Offline
What you need to do is make another list.
Each character is an item on the list: (you can make a txt file and import the list, it's easier)
A
B
C
the rest of the letters, numbers
.
?
the rest of the punctuation and symbols
And so then you have to find which item # H is on the list. (it should be 8)
Then, each item number on the list is the exact same number as the costume number of the character.
That's the easiest way, I think.
Offline
kayybee wrote:
What you need to do is make another list.
Each character is an item on the list: (you can make a txt file and import the list, it's easier)
A
B
C
the rest of the letters, numbers
.
?
the rest of the punctuation and symbols
And so then you have to find which item # H is on the list. (it should be 8)
Then, each item number on the list is the exact same number as the costume number of the character.
That's the easiest way, I think.
So it decodes it into numbers which can be used to make the message?
Offline
so what about double digits?
Offline
also, how can I import a list from a txt file?
Offline
make a list,
make sure it's showing,
right click it (the actual list on the stage)
import.
each enter will make a new item. So the above steps will be four items.
To answer your question, i shall tell you the process that I would use.
The user types something in.
You set the input as a result.
You set each character (and space) as a separate item on a list.
You take each item, find the costume #, then stamp. Delete that letter and move onto the next.
Rinse and repeat.
Offline
I found a better way, a list called sent, a list called decode, and a list called output.
first it makes an item of every letter from the answer, say hello world would become
h
e
l
l
o
w
o
r
l
d
decode is a list of letters and numbers, like a1, b2, c3 etc.
it checks each letter from sent and finds the matching letter on decode and then gets the number from the end (letter 2&3, but if it only has one it will still work) it adds each code to output and tells the letter to switch to costume item "count" of list output (count changes every letter)
[blocks]
<when green flag clicked>
<set{ count }to( 1 )}>
<set size to( 10 )%>
<clear>
<go to x -200 )y 50 )>
<repeat( length of output )>
<switch to costume[ item <{ count }> of output ]>
<stamp>
<change x by( 20 )>
<change{ count }by( 1 )}>
<end>
[/blocks]
it changes to the code, stamps, moves on.
Last edited by my-chemical-romance (2011-10-03 18:00:17)
Offline
Ok, to explain the costume thing better, look at the block. It says "switch to costume [name]". Scratch figures out if the variable you put in there is a string or not. If it is, it uses that string to define 'name'. If there is no string match up, it does not switch costumes. If the value is an a number, even a floating number, it rounds the number and uses that for the costume #, not the costume name. So if you have a variable equal to the string "a" and a costume called "a" it will switch to that costume.
As for importing .txt files as lists, what you must do is make sure the .txt file is spaced how you want it. Scratch interprets every new line as a new item, so be sure to enter in between each item in the .txt file. Then you would right-click on the list and select import and then the .txt file. You cannot have Scratch import a list on it's own, it must be done semi-manually.
Offline