1

How to make a script that inserts # character every x character?

I already tried to make this by creating a script down below.

This is my script, but it doesn't work, somewhy...

/// string_linebreak(str,w)

var str, w, p, l;

str = argument[0];
w = argument[1];
l = string_length(str);

// Linebreakes
for (p = 0; p <= l; p ++) {
    if (p mod w) {
        string_insert("[@l]", str, p);
    }
}

str = string_replace_all(str, "[@l]", "#");

return str;

I except to get a string with # character every x character.

younyokel
  • 327
  • 2
  • 15
  • I also tried `if ((p mod w) == 0) then` instead `if (p mod w) then`. I didn't work. – younyokel Jun 01 '19 at 13:04
  • If you just want to draw this, you can try using `draw_text_ext`, this will automatically wrap text. – Rob Jun 04 '19 at 14:02
  • @Rob Quist, I have my own script that draws coloured text by reading and deleting tags so it will not work. – younyokel Jul 21 '19 at 06:05

1 Answers1

1

Try this.

//string_linebreak(str,w)
var str = argument0;
var spacing = argument1;
var leng = string_length(str);
var output = "";

var p;
for (p=1; p<=(leng+1); p++)
{
    output += string_char_at(str,p);
    if ((p mod spacing)==0)
    {
        output += "#";
    }
}

return output;

In case you were curious, the problem is that you are trying to iterate through each character but you're also adding characters to the string as you do so.

Orion DeYoe
  • 102
  • 1
  • 11