String Parse Error

Azlier

Old World Ghost
Reaction score
461
Razelle.JPG
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Does this use a dictionary or something? Or does it randomly convert stuff to other stuff?
 

quraji

zap
Reaction score
144
String stuff? You should have come straight to me! ;)

Well let me start by saying this method isn't very robust :p

The problem is that you don't reset the values in your Sep array. This can cause errors with a lot of different inputs. (notice "death to" displays correctly if you type it before "death to the hill"; you can also try something like "death to the hill, death" then type "death to the hill").
Another interesting issue is that if you type translatable input, then gibberish, the method will string together translated words from the previous input (try "death to the hill", then "jjjjjjjjjjjjjjj" or something).

Both of these problems can be quick-fixed by either resetting the arrays or simply using local arrays (the latter solution I like better).

But, that's just a quick fix. Once again the whole thing isn't very robust and I wouldn't be surprised if more issues popped up.

I like the idea you have going here (I have an unfinished system like this - for translating into pirate speak :p), but there's a few things missing... What if I want a word with a separator inside it to be translated? Also, why can't I add separators to my custom language?
Unless you want the features of this language thing to be kept to a minimum and have very rigid rules, then be prepared for a lot of work, strings are a pain in the ass.


EDIT: I whipped up a .translate version of my own, keeping your concept but removing the unnecessary stuff (arrays, reconstructing). When a separator is found, it immediately translates the word before it and adds the translation and the separator to the result. At the end of this loop it translates the rest if there is anything left of the source string that wasn't parsed (as the loop will exit when it no longer finds a separator in the string, which could be prematurely if the string doesn't end in a separator). This eliminates the need for the arrays (and the problems they cause :p).
JASS:
    method translate takes string source returns string
        local integer i = 0
        local string result = " "
        local string s
        loop
            exitwhen (i==StringLength(source))
            set s = SubString(source, i, i+1)
            if (LoadBoolean(ht, 0, StringHash(s))) then // separator found
                set result = result + .translateWord(SubString(source, 0, i)) // translate the word and add it to the result
                set result = result + s                                       // add the separator
                set source = SubString(source, i+1, StringLength(source))     // set source to itself minus what has been parsed
                set i = -1 // reset i (-1 so it is incremented to 0 after the endif)
            endif
            set i = i + 1
        endloop
        if (i>0) then // there's some unparsed string left (with no separators, so should be a word)
            set result = result + .translateWord(source)
        endif
        return result
    endmethod


I also suggest that you change your .translateWord method to this (unless you want to force people to define every possible combination of characters! :p):
JASS:
    method translateWord takes string word returns string
        local string s = LoadStr(ht, this, StringHash(word))
        if (s == null) then
            debug call BJDebugMsg("Language Warning: Undefined word \"" + word + "\".")
            return word
        endif
        return s
    endmethod


Anyways, hope that helps out, and I'd be glad to provide any further assistance! I have a strange attraction to string stuff...
 

Azlier

Old World Ghost
Reaction score
461
Thank you, quraji.

Yes, this language thing is very simple. It can't handle anything other than English -> Made up language. And that language must follow English grammar rules.

It now works perfectly, and is probably ready for submission.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top