Login | Register

Scramble letters

June 30, 2006, 23:54 by Calle
[loading]
-->
A recersah sohws taht if olny the frist and the lsat ltters in a wrod is the smae you can raed wihtuot prbolmes. Therefore I have created this script to try the theory out. You it let’s people input a sentence and then it scrambles the order of the letters. Look carefully at the commenting to understand the code.

<div style="clear: both;">text = get_string("Enter a phrase:","";);
text +=" end"
txt = "";
words[100] = "";

tts=text;
delimiter=" ";

counter=0;

do
{
dlpos=string_pos(delimiter,tts);
//Finds the delimiter “ “
words[counter]=string_copy(tts,1,dlpos-1);
// Copies the next word
tts=string_delete(tts,1,dlpos+string_length(delimiter)-1);
counter+=1;
} until (string_pos(delimiter,tts)=0)
//starts all over unless condition is met

global.splitvals[counter]=tts;
counter+=1;

d = 0;
while(d<counter) {
//Tells it to run until d>counter (counter is the
//number of all words, which we can see in previous code

a = 0;
txt += string_char_at(words[d],1);
//Save the first letter
words[d] = string_delete(words[d],1,1);
//delete the saved letter
while(a<string_length(words[d])) {
add =
string_char_at(words[d],floor(random(string_length(words[d]))));
//randomly picks out a letter
txt += add;
words[d] = string_delete(words[d],string_pos(add,words[d]),1);
//deletes taken letters
a+=1;
}
txt += words[d];
txt += " ";
d+=1;
}

show_message("Whatever you wrote, you should still be
able to read it without problem, isn't that amazing?##"+txt);
//Final output stored in txt
</div>

I realize this code might not be the most useful one, but the test is fun, I think, and if you decide to use this script anywhere, please give credits to this site.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games