Code diagnostics plz

Posted by Taizen Chisou on May 8, 2012, 5:35 p.m.

Honestly, I just put this together, so perhaps it was utterly foolish of me to expect this to work.

The idea is that the text object takes it's given string and separates it into smaller strings each with different parameters.

It takes a string like

"The idea is /inot /cto destroy the /bstrange monsters, /cbut rather to take them alive for further inspection by /ySeamus."

and turns it into

"The idea is not to destroy the strange monsters, but rather to take them alive for further inspection by Seamus."

For some reason, it doesn't do this.

All of the ministrings are blank and the formatting is not present.

length = string_length(str);

while(parseStringPos < length)
    {
    parseStringPos += 1;
    changed = false;
    
    if (string_char_at(str,parseStringPos) == "")
        {
        parseStringPos+=1;
        
        if ((string_char_at(str,parseStringPos) == "i") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            stringFormatting[currentString] = 1;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            parseStringPos += 1;
            }
        if ((string_char_at(str,parseStringPos) == "b") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            stringColor[currentString] = c_blue;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            parseStringPos += 1;
            }
         if ((string_char_at(str,parseStringPos) == "g") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            stringColor[currentString] = c_lime;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            parseStringPos += 1;
            }
         if ((string_char_at(str,parseStringPos) == "r") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            stringColor[currentString] = c_red;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            parseStringPos += 1;
            }
          if ((string_char_at(str,parseStringPos) == "y") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            stringColor[currentString] = c_yellow;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            parseStringPos += 1;
            }
          if ((string_char_at(str,parseStringPos) == "s") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            stringEffect[currentString] = 1;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            parseStringPos += 1;
            }
          if ((string_char_at(str,parseStringPos) == "c") && (changed = false))
            {
            changed = true;
            currentString += 1;
            totalStrings += 1;
            parseStringPos += 1;
            stringStartXinc[currentString] = stringStartXinc[currentString-1]+string_width(stringText[currentString-1]);
            stringStartYinc[currentString] = stringStartYinc[currentString-1];
            }
                
        }
    else if (string_char_at(str,parseStringPos) != "#")
        {
        stringText[currentString] += string_char_at(str,parseStringPos);
        }
    else
        {
        currentString += 1;
        totalStrings += 1;
        stringLines += 1;
        stringStartXinc[currentString] = 0;
        stringStartYinc[currentString] = stringLines * 12;
        stringColor[currentString] = stringColor[currentString-1];
        stringFormatting[currentString] = stringFormatting[currentString-1];
        stringEffect[currentString] = stringEffect[currentString-1];
        }
    }

Comments

Alert Games 12 years, 7 months ago

@Charlie: What he's saying is that if you use images of the individual characters, you use less space because you dont have an image for every text. That is, if you have many in the game. It also would make loading longer and the filesize much larger. Also, if you have to make changes later, you actually have to edit the visual file of it rather than just changing the text. :(

Also, this:

Quote:
This has been done before, and is on the GMC..I think Fox-NL made it.

Charlie Carlo 12 years, 7 months ago

I'm aware of the impracticality, most things I do are impractical.

Taizen Chisou 12 years, 7 months ago

Case in point: he codes in Drag n Drop.

:V

Anyway, Juju, thank you so much

although i'm not noticing any real differences here

I'm gonna try it out in the morning and see if anything happens.

Taizen Chisou 12 years, 7 months ago

As for the bit about this being done before on the GMC, I dun wanna

besides i wanted to have a text engine support this and not freeze the game

Juju 12 years, 7 months ago

Me being a bellend aside, there are some things you can do with text-all-in-an-image that isn't possible with standard font maps. Just not a lot, that's all.

There were 3 main issues:

1) Lots of if-statements is are silly for readability

2) You weren't actually checking for the begin-tag character

3) Your arrays weren't all the same size

Incidentally, if you have that "uninitialised variables equal zero" option turned on, turn it off right now. It will help you track down spelling errors so much faster.

Taizen Chisou 12 years, 7 months ago

Well, um, the 64d blog editor rejects backslashes :I

I had to change them to forward slashes.

As for the arrays, huh?

I couldn't get the parser to add untagged text ("c = 'clear'") because my test string was "hello."

I'm implementing your version in a minute, see if it works.

I haven't used that for years :<

Juju 12 years, 7 months ago

Good luck.

Taizen Chisou 12 years, 7 months ago

uh

i'll fix this eventually

You can't really tell, but the word "eeextbox" shakes.

in the meantime, i should totally fix the c command for normalizing the text

and maybe even the weird bit with the first few letters

Toast 12 years, 7 months ago

Wait a second

JUJU GAVE YOU CODE

EVERBODIES IS DISQUALIFIEDS

JuurianChi 12 years, 7 months ago

Toast: Wait a minute…r u tyin to cheat?

Taizen: GoobyToast, plz!