Okay. So I have a function here that I made by myself, but I have a feeling it is unhealthily inefficient. Basically, It is a function that takes the string you give it and the maximum length of characters allowed on a line, and breaks the message up into segments that will fit into two lines. If it goes over two lines of text, it creates another portion of it that will carry over to the next "message". Example: Max allowed characters: 10 String = "Here is a typical message." This will output: string1: "Here is a#typical" string2: "message."
Typical was placed on the second line because although 10 characters had not been reached on the first line, it was a whole word in itself (makes sense obviously)
ANYWAY, here is the script I'm using (feel free to optimise it and/or write your own in replacement :p)
///scr_text_filter_word(string text, real character_line_limit) text = argument0; var maxlength, textlength, usestring, usetext, i, currentpos, endword, newline, attemptbreak; maxlength = argument1; usetext = text; usestring = ""; done = 0; ii = 0; currentpos = 1; endword = 0; newline = 1; attemptbreak=0;
while (done == 0) { attemptbreak=0; if(string_length(usetext) > maxlength) { for (i = 1; i <= string_length(usetext); i += 1) { if(attemptbreak == 1) break; currentpos = i; if(string_char_at(usetext,i) == " ") { for (iii = 1; iii < string_length(usetext)-currentpos; i+=1) { if(string_char_at(usetext,i+iii) == " ") { endword = iii; break; } } if(currentpos + endword > maxlength) { var newtext; newtext = string_copy(usetext,1,currentpos); if(newline == 1) { global.g_showmessage[ii+1] = newtext; ii+=1; newline=0; } else { newtext = string_insert("#",newtext,1); global.g_showmessage[ii] = global.g_showmessage[ii]+newtext; newline=1; } usetext = string_copy(usetext,currentpos+1,string_length(usetext)-currentpos); attemptbreak = 1; } } } } else { if(newline == 1) { global.g_showmessage[ii+1] = usetext; ii+=1; } else { usetext = string_insert("#",usetext,1); global.g_showmessage[ii] = global.g_showmessage[ii]+usetext; } done = 1; global.g_msgtot = ii; } }
|