ID:139920
 
I was experimenting, trying to make a Chat filter that will filter words even when covered up by punctuation and other things. All of this works, but when I try to put their punctuation back in(or do a period if they didn't have any), it doesn't work. I used copytext() to find the last character, and used a list of punctuation to see if that character was punctuation or a character. But after I noticed it wasn't working quite right, I had it add the variable I assigned the copytext() to show up instead of a period, it made another letter.

Is this a bug, or is it supposed to be this way? If it is supposed to be this way, is there a workaround?
It helps if you have code so we can find your error.
In response to Popisfizzy
Not sure why code is needed to know if copytext() reads punctuation or not, but whatever.

var
punctuation=list(".","!","?","*")
message_length=length(M)
message_last=copytext(M,message_length-1,message_length)
if(message_last in punctuation)
M=copytext(M,1,message_length)
var/first_letter=copytext(M,2,3)
var/other_letters=copytext(M,3)
M=" [uppertext(first_letter)][other_letters]"
M+="[message_last]"
else
M=copytext(M,1,message_length)
var/first_letter=copytext(M,2,3)
var/other_letters=copytext(M,3)
M=" [uppertext(first_letter)][other_letters]"
M+="."


Partial credit to Polaris8920 for some pieces of the code and inspiration.
In response to Albro1
... you're clearly using copytext() to copy the punctuation to determine if it's in your list of punctuation, so why do you think copytext() doesn't work on punctuation?
In response to Popisfizzy
When I test it in-game, and I type a ! or ? at the end of my message, it does not work. I also decided to replace the line that says:
M+="."

With:
M+="[message_last]"

And the results became the last letter of my message.

For example if I were to type:
Hi!
It would show:
Hii
In response to Albro1
Have you, out of curiosity, read the reference on copytext()?
In response to Popisfizzy
I have. Why do you ask?
In response to Albro1
Read it again.
In response to Popisfizzy
I did, and saw some flaws in my code that I fixed. It still did not fix my problem.

For example, I forgot that End was the position immediately AFTER the last checked character. So, I needed to change message_length to message_length+1, or just let it default itself.
In response to Albro1
A problem with your own test examples was that you had poor input. Every sentence ended with punctuation, so you had selection bias. Your code will simply fail to copy the last character, regardless of what the content of the character is.
var
text = "123456"
alpha = copytext(text, 1, 4)
beta = copytext(text, 4, 7)

if((alpha + beta) == text)
world << "Equivalent!"
else
world << "Not equivalent!"

This code will output "Equivalent!", as it does copy all characters, including the last one. copytext() is working fine, and any other problems you have are a result of your own bugs, meaning this thread should be moved to code problems.
In response to Popisfizzy
After some working with it, I found a workaround that works just as well, if not better than the previous code was...expected to work. Thanks for the help anyways!