Legacy GM Can you help with skipping string_insert()?

E

Edwin

Guest
I need to use string_insert() function with specific variable that keeps the position of where I need to insert my string with string_insert(). The string what I'm gonna insert is an alpha tag. Other script will delete this tag and make the text transparent from position keeping variable to end. In this simple way, I will make the typewriter effect.

The problem is that I've failedly tried to create the script that gonna skip my other tags and insert an alpha tag using string_insert() function.

So my script looks like this:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, i;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);

// To get the string inside the tags
for (var p = 1; p < l; p ++) {
   if (string_char_at(str, p) == "[" && string_char_at(str, p+1) == "c" && string_char_at(str, p+2) == "=") {
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
   }
}

// Return the string with substring
return string_insert(substr, str, index);
Tags that script should skip are [c=...] and [/c]. Please answer if you know how to implement this. I tried to make it by my own but did not work.

Thank you for your care.
 

jo-thijs

Member
I need to use string_insert() function with specific variable that keeps the position of where I need to insert my string with string_insert(). The string what I'm gonna insert is an alpha tag. Other script will delete this tag and make the text transparent from position keeping variable to end. In this simple way, I will make the typewriter effect.

The problem is that I've failedly tried to create the script that gonna skip my other tags and insert an alpha tag using string_insert() function.

So my script looks like this:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, i;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);

// To get the string inside the tags
for (var p = 1; p < l; p ++) {
   if (string_char_at(str, p) == "[" && string_char_at(str, p+1) == "c" && string_char_at(str, p+2) == "=") {
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
   }
}

// Return the string with substring
return string_insert(substr, str, index);
Tags that script should skip are [c=...] and [/c]. Please answer if you know how to implement this. I tried to make it by my own but did not work.

Thank you for your care.
It looks like you had the right idea, right up until this line:
Code:
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
You assign a value to i, but you never do anything else with this variable.
This makes it so the for loop never does anything.
Try this:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// To get the string inside the tags
for (var p = 1; p <= l - cstl; p ++) {
   if (string_copy(str, p, cstl) == cst) {
        var tag_length = string_pos(cct, string_delete(str, 1, p + cstl - 1)) + cctl - p;
        str = string_delete(str, p, tag_length);
        l -= tag_length;
        p --;
        continue;
   }
}

// Return the string with substring
return string_insert(substr, str, index);
 
E

Edwin

Guest
It looks like you had the right idea, right up until this line:
Code:
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
You assign a value to i, but you never do anything else with this variable.
This makes it so the for loop never does anything.
Try this:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// To get the string inside the tags
for (var p = 1; p <= l - cstl; p ++) {
   if (string_copy(str, p, cstl) == cst) {
        var tag_length = string_pos(cct, string_delete(str, 1, p + cstl - 1)) + cctl - p;
        str = string_delete(str, p, tag_length);
        l -= tag_length;
        p --;
        continue;
   }
}

// Return the string with substring
return string_insert(substr, str, index);
Thank you for replying.

I know that my code doesn't do anything. I simply just took the i function to get the cet and string whatever inside the tag.
 
E

Edwin

Guest
It looks like you had the right idea, right up until this line:
Code:
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
You assign a value to i, but you never do anything else with this variable.
This makes it so the for loop never does anything.
Try this:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// To get the string inside the tags
for (var p = 1; p <= l - cstl; p ++) {
   if (string_copy(str, p, cstl) == cst) {
        var tag_length = string_pos(cct, string_delete(str, 1, p + cstl - 1)) + cctl - p;
        str = string_delete(str, p, tag_length);
        l -= tag_length;
        p --;
        continue;
   }
}

// Return the string with substring
return string_insert(substr, str, index);
Hello again, I think you didn't understand my question correctly. Your script deletes the tag and value inside it, but I mean a script that inserts substring and skips certain strings (literally skips).

Something like this:


It still not perfect because it can not skip the [/c] tag.

So this is code that I made:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl, tag_string, tag_length;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// Get symbols that inside the tags
for (var p = 1; p <= l; p ++) {
    if (string_copy(str, p, cstl) == cst) {
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
        if (index > string_pos(cst, str)) {
            return string_insert(substr, str, (index + string_length(i) - cstl) - 1);
        } else {
            return string_insert(substr, str, index);
        }
    }
}
If there are comments, I’ll be happy to hear them
 

jo-thijs

Member
Hello again, I think you didn't understand my question correctly. Your script deletes the tag and value inside it, but I mean a script that inserts substring and skips certain strings (literally skips).

Something like this:


It still not perfect because it can not skip the [/c] tag.

So this is code that I made:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl, tag_string, tag_length;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// Get symbols that inside the tags
for (var p = 1; p <= l; p ++) {
    if (string_copy(str, p, cstl) == cst) {
        i = string_copy(str, p + cstl, string_pos(cct, string_delete(str, 1, p + cstl)));
        if (index > string_pos(cst, str)) {
            return string_insert(substr, str, (index + string_length(i) - cstl) - 1);
        } else {
            return string_insert(substr, str, index);
        }
    }
}
If there are comments, I’ll be happy to hear them
Oh, I indeed misinterpreted what you asked for.

Try this instead:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl, tag_string, tag_length;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// Get symbols that inside the tags
var p = 0;
while (index > 0) {
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else if (string_copy(str, p, cctl) == cct) {
        p += cctl;
    } else {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
 
E

Edwin

Guest
Oh, I indeed misinterpreted what you asked for.

Try this instead:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl, tag_string, tag_length;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// Get symbols that inside the tags
var p = 0;
while (index > 0) {
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else if (string_copy(str, p, cctl) == cct) {
        p += cctl;
    } else {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
Edit: oops sorry my mistake...

Thank you, I'll check it out.
 
E

Edwin

Guest
Oh, I indeed misinterpreted what you asked for.

Try this instead:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl, tag_string, tag_length;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// Get symbols that inside the tags
var p = 0;
while (index > 0) {
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else if (string_copy(str, p, cctl) == cct) {
        p += cctl;
    } else {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
Oh yeah, that works! Thank you so much again!
 
E

Edwin

Guest
Oh, I indeed misinterpreted what you asked for.

Try this instead:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, l, cstl, cctl, tag_string, tag_length;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

l = string_length(str);
cstl = string_length(cst);
cctl = string_length(cct);

// Get symbols that inside the tags
var p = 0;
while (index > 0) {
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else if (string_copy(str, p, cctl) == cct) {
        p += cctl;
    } else {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
Hey, I don't want to disturb you but if you aren't busy, I tried to add other tags except [c=..] but it caused some inaccuracies in the inserting position.

So I simply copypasted that loop you send me.
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, ast, aet, act, l, cstl, cctl, astl, actl, p;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

ast = '[a=';
aet = ']';
act = '[/a]';

l = string_length(str);

cstl = string_length(cst);
cctl = string_length(cct);

astl = string_length(ast);
actl = string_length(act);

p = 0;

// Skip colour tag
while (index > 0) {
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else
    if (string_copy(str, p, cctl) == cct) {
        p += cctl - 1;
    } else {
        p ++;
        index --;
    }
}

// Skip alpha tag
while (index > 0) {
    if (string_copy(str, p, astl) == ast) {
        p += astl;
        p += string_pos(aet, string_delete(str, 1, p - 1));
    } else
    if (string_copy(str, p, actl) == act) {
        p += actl - 1;
    } else {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
I also tried to merge alpha and colour tags skipping inside
Code:
while (index > 0) {
    // ...
}
this while loop but that drove the game crazy.
 

jo-thijs

Member
Hey, I don't want to disturb you but if you aren't busy, I tried to add other tags except [c=..] but it caused some inaccuracies in the inserting position.

So I simply copypasted that loop you send me.
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, ast, aet, act, l, cstl, cctl, astl, actl, p;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

ast = '[a=';
aet = ']';
act = '[/a]';

l = string_length(str);

cstl = string_length(cst);
cctl = string_length(cct);

astl = string_length(ast);
actl = string_length(act);

p = 0;

// Skip colour tag
while (index > 0) {
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else
    if (string_copy(str, p, cctl) == cct) {
        p += cctl - 1;
    } else {
        p ++;
        index --;
    }
}

// Skip alpha tag
while (index > 0) {
    if (string_copy(str, p, astl) == ast) {
        p += astl;
        p += string_pos(aet, string_delete(str, 1, p - 1));
    } else
    if (string_copy(str, p, actl) == act) {
        p += actl - 1;
    } else {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
I also tried to merge alpha and colour tags skipping inside
Code:
while (index > 0) {
    // ...
}
this while loop but that drove the game crazy.
It needs to be one loop:
Code:
/// string_insert_tag(substr,str,index)

// Declare variables
var substr, str, index, cst, cet, cct, ast, aet, act, l, cstl, cctl, astl, actl, p;

// Set variables
substr = argument[0];
str = argument[1];
index = round(argument[2]);

cst = '[c=';
cet = ']';
cct = '[/c]';

ast = '[a=';
aet = ']';
act = '[/a]';

l = string_length(str);

cstl = string_length(cst);
cctl = string_length(cct);

astl = string_length(ast);
actl = string_length(act);

p = 0;

// convert "index" (the logical index, the one from the input) to "p" (the internal index, of the actual representation)
while (index > 0) {
    // Skip colour tag
    if (string_copy(str, p, cstl) == cst) {
        p += cstl;
        p += string_pos(cet, string_delete(str, 1, p - 1));
    } else
    if (string_copy(str, p, cctl) == cct) {
        p += cctl - 1;
    } else
    // Skip alpha tag
    if (string_copy(str, p, astl) == ast) {
        p += astl;
        p += string_pos(aet, string_delete(str, 1, p - 1));
    } else
    if (string_copy(str, p, actl) == act) {
        p += actl - 1;
    } else
    // Count single character
    {
        p ++;
        index --;
    }
}

return string_insert(substr, str, p);
 
Top