Reverse Sentence Order gamemaker


create event: 

msg = "one two three for five"; //string to split
reversed="";//initialize string
splits[0]="";//initialize array
splitBy = " "; //string to split the first string by
slot = 0;//starting slot
str2 = ""; //var to hold the current split we're working on building


for (var i = 1; i < (string_length(msg)+1); i++)
{
currStr = string_copy(msg, i, 1);//get character 1 by 1
if (currStr == splitBy)//split if [space] found
{
splits[slot] = str2; //add this split to the array of all splits
slot++;
str2 = "";
}
else
{
str2 = str2 + currStr;
splits[slot] = str2;//add last word
}
}
//add back to a new string

for(var i = slot; i >-1 ; i -= 1)//start a number of slots and reduce i by one each loop
{
reversed+=splits[i]+" ";
}


draw event:

draw_text(50,40,reversed);




The Weekender: Moon metaphors, procrastinating monks, and a visit to a cheese factory

What we’re reading, watching, and listening to this week ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ...

Contact Form

Name

Email *

Message *