• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Getting a specific char of a string

Status
Not open for further replies.
Level 11
Joined
Sep 30, 2009
Messages
697
Is there another way than using SubString(string, x, x +1) ?

I need this for my the UI System I am creating which will use Texttags with automatized line break so I have written myself a small library, but I am not sure if it would work correctly:

JASS:
library SubStringLastWord
    
    function SubStringLastWord takes string s, integer start, integer end returns string
        local string sub     = SubString(s, start, end)
        local string sub2    = ""
        local integer End = end
        loop
            exitwhen sub != " " and sub2 == " "
            set End = End - 1
            set sub2 = sub
            set sub = SubString(s, End - 1, End)
        endloop
        set sub = SubString(s, start, End + 1)
        return sub
    endfunction    
    
endlibrary
 
Sadly, that is the only way. I've done the same thing that you are doing, and it is very annoying. xP You can reach the op limit pretty fast.

This library might be useful for you:
http://www.hiveworkshop.com/forums/1886277-post379.html

I'm gonna switch to use it in my map eventually. It will at least get the string sizes for you, so that part will be less annoying. (so you can just add up the sizes of words and break to the next line when it gets past a certain value)

EDIT: You may want to check this post out:
http://www.hiveworkshop.com/forums/...-code-snippets-40758/index26.html#post1889717

It does what you need, hopefully. :)
 
Last edited:
Level 11
Joined
Sep 30, 2009
Messages
697
Hmm thanks the scripts look nice, but the second one has a little issue. It gives an error that the function IsStringHexCC can't be found because its private. Removing the private removed the error ;)

EDIT: Implemented your system and it works kinda fine, but I don't really know how to handle it with the texttags size :/ Would be nice if someone could give me a calculation based on the size of the texttag.
 
Last edited:
Hmm thanks the scripts look nice, but the second one has a little issue. It gives an error that the function IsStringHexCC can't be found because its private. Removing the private removed the error ;)

Sorry, I forgot to update the StringSize's version. :p

EDIT: Implemented your system and it works kinda fine, but I don't really know how to handle it with the texttags size :/ Would be nice if someone could give me a calculation based on the size of the texttag.

Hmm.. I'm not sure what you mean. I'll attach a test map. It worked fine for me:
lineBreak04.png

The only thing to watch out for is that texttags may automatically line break after a certain string length, or something like that. Having the width less than 400 will probably fix that. (otherwise it will shift the texttag upwards)
 

Attachments

  • TestMapA.w3x
    31.4 KB · Views: 52
Level 11
Joined
Sep 30, 2009
Messages
697
The only thing to watch out for is that texttags may automatically line break after a certain string length, or something like that. Having the width less than 400 will probably fix that. (otherwise it will shift the texttag upwards)

Well the linebreaking works just fine, but I want the size of the texttags be configurable, which would require a linebreak after a lower string length or a higher string length depending on the size.

After a bit of testing taking the real given by your system multiplied with 14.5 and divided by the font size of the texttag seemed to look fine.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,178
You could write a custom function which basically wraps SubString(string, x, x +1).

In JNGP it would probably automatically inline as well but it would still look neater.

JASS:
function GetChar takes string s, integer pos returns string
    return SubString(s, pos, pos +1)
endfunction
 
Status
Not open for further replies.
Top