sending a long string in chunks to a type field

Blitz3D Forums/Blitz3D Programming/sending a long string in chunks to a type field

stayne(Posted 2015) [#1]
I need to send each part (string) of a long sentence, that will be word-wrapped, to a type field then draw them with Draw3D's Text3D function since the latest version doesn't offer word wrap. I'm going to include the two functions I have lined up for this:



I'm adding sentences via AddChat and some of them are pretty long. So...any ideas to break the strings up and wrap them? Sorry this is a bit enigmatic.


Midimaster(Posted 2015) [#2]
With INSTR() you can look for a SPACE character With LEFT() and MID() you can divide the string.

Test$="abc def ghijk l mno"
Here%=0
Part$=""
Repeat 
    Here=Instr(Test," ")
    If Here=0
        Part=Test
    Else
       Part= Left(Test,Here-1)
    EndIf
    Print "PART=" + Part 
    Test=Mid(Test,Here+1)
Until Here=0


If you want to cut sentences longer than f.e. 30 characters, add a OFFSET test:
Test$="abc def ghijk l mno  fjgj jgjr rjghj jjtiu djjgj djfjg jglvjbls  jjgj esk"
Here%=0
Offset%=30
Part$=""
Repeat 
    NextHere%=0
    Here=0
    Repeat
        Here=Instr(Test," ",Here+1)
        NextHere=Instr(Test," ",Here+1)
    Until NextHere>Offset Or Here=0 Or NextHere=0
    If NextHere=0
        Part=Test
    Else
       Part= Left(Test,Here-1)
    EndIf
    Print "PART=" + Part + " (LEN=" + Len(Part) +")"
    Test=Mid(Test,Here+1)
Until NextHere=0



Bobysait(Posted 2015) [#3]
here is two methods to split sentence
the first use only the width of the chatbox
the second use logic splitters to split sentence while preserving words at best. (uses ., and space, but you can add :; etc ...)

You might want to fit MSG_MAX_LINES to your needs. Basically, it's the maximum number of lines available for a message.




[EDIT]
Damned ! 15 minutes too late :)


Matty(Posted 2015) [#4]
Do you know how much room in pixels you have to display the text?
Do you know how wide the text string is in pixels?
If you know the string is 100 pixels wide but you have only 30 pixels display area for example simply find the first tab or space prior to '30/100' fraction of the string length in and cut it there and repeat with the remainder of the string.....basic idea/premise behind a solution.


stayne(Posted 2015) [#5]
Thanks a lot guys I'll dig into this later this afternoon.


stayne(Posted 2015) [#6]
Midimaster I am having an issue with strings like this:

AddChat("> "+"<#f00>"+c\name+"<#fff>"+" hit "+c\attacktargetname+" for "+c\damage+" points of damage!")

Is your code parsing +...+ strings as well?


Midimaster(Posted 2015) [#7]
If there is an "+" in the string it will be handled as a normal character...


Or do you mean, whether also the "+" can be the point, where the string should be divided? Yes, that is possible.
Here=Instr(Test,"+")



But your sample strings will not contain any "+" at the end:
the command...
"> "+"<#f00>"+c\name+"<#fff>"+" hit "+c\attacktargetname+" for "+c\damage+" points of damage!"

becomes this strings....
"> <#f00>STAYNE<#fff> hit PETER for 999 points of damage!"


If you want to devide the strings on exaclty the old points, insert a new separator sign:
"> |"+"<#f00>|"+c\name+"|<#fff>|"+" hit |"+c\attacktargetname+"| for |"+c\damage+"| points of damage!"


now search for the "|"
Here=Instr(Test,"|")



stayne(Posted 2015) [#8]
It's wrapping the string like so:

Guard Stayne
hit soandso for 4 points of damage.

Still working at it...thanks man. The <#xxx> entries are for Text3D color. I have a feeling this function is parsing those as well.


Bobysait(Posted 2015) [#9]
both its code and mine don't care about "invisible" tags, so it's logical that the text is cut too early.
If you want to split only according to the "real text", you'll have to parse all the string and map the valid characters.
A simple tokenizer should do the job pretty well.



ps : Don't judge me !
Nobody like purple mice !


stayne(Posted 2015) [#10]
Bobysait you have some serious skills there my friend.


Bobysait(Posted 2015) [#11]
Thanks, but I don't pretend to own real skills, it's just experience.
I've been programming with blitz3d for more than 10 years.
Like many others here (*), almost everything asked on the forum, we have already experienced it.

BTW : Hope the code will help




(*) except for Xylvan ... He was naturally born good. So, since he began to code, he keeps on doing the same candy world, again and again and again ^_^
private joke ... I could (and/or should) have skip this one as it's totally free and irelevant ... but, you know ... :)