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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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