GMS 2 Special characters in a string?


I'm fairly new to GML, so this question may sound a little nooby. It's also my first post! :)

So I've made a typer object which types out a string, letter by letter, which works fine. I've also made it so that when it detects a certain character, it does some kind of action. Like pausing or changing colour or whatever.

switch(string_char_at(msg[page], count)){
       case ".":
           stopped = true;
           alarm[0] = 15; 
While the above works, I thought it'd be better if I could do some kind of rich text thing, where it removes the special symbols from the actual text but still carries out the action.

msg[0] = "Hello, !3 this is a test";
where !3 indicates a delay for 3 seconds. !5 could be 5 seconds, !10 could be 10, etc.

How would I go about this? :/


Exclamation mark might not be the best choice as you may need it in normal text. Use something less likely such as pipe symbol (|) or underscore (_). It is best to wrap the special command with the symbol so you know exactly where it starts and ends, like |100|. Then you can write their handling with roughly the following logic:
1. While writing out text, look for special symbols that start an action.
2. Upon detecting a special symbol, note its position in string and start another loop from that position onwards to find the end.
3. Once end is found, copy everything between the symbols and process the command with it. For example, |10| would grab the 10 and set a ten second wait with it.
4. Cut the command sequence out of the string and continue as normal.
Cutting out the command sequence should be as simple as using string_replace where you replace it with nothing. It only replaces the first found instance of a string, which always should be the command currently being processed.


GameMaker also supports 16-bit characters... I think you enter them into the string by doing "\u" followed by four hex digits (e.g. "\u0100" for character #256). This could make the parsing a lot easier, since GameMaker considers "\u0100" to be a single character.

So if you had your string:
msg[0] = "Hello,\u0103 this is a test";
You could loop through the string, and set up a simple if statement...
else if((ord(string_char_at(msg[0],i))&$FF00)==1){ // <-- if you don't understand this, you need to do some research on "bit masking"