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.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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