Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [ AGK][Text] How to split any phrase out semi-equally?

Author
Message
Alex Goaga
9
Years of Service
User Offline
Joined: 6th Nov 2015
Location:
Posted: 28th Nov 2016 20:37
Hey guys,

For example i will use the following phrase

a_text$ = "This is a text message with a long phrase that i would like to split it semi-equally in two or more sentences"
CreateText(100000,a_text$)
print (GetTextLength( 100000 ))

it can be noticed that the GetTextLength will display the number 109 ( including spaces )
How i can make a function that would "cut" the long phrase in 2 / 3 sentences like

function split_my_phrase ( text$ , text_position_x, text_position_y, how_many_sentences) // example in 3 semi-equal parts

how_long_is_it = GetTextLength( text$ ) // 109
math = how_long_is_it / how_many_sentences // that means => 109 / 3 = 36.333333

createtext(1 , "first 36 characters")
createtext(2 , "middle 36 characters")
createtext(3 , "last 36 characters")

SetTextPosition(1, text_position_x, text_position_y)
SetTextPosition(2, text_position_x, text_position_y)
SetTextPosition(3, text_position_x, text_position_y)

endfunction

How i can make something like this to be displayed?

36.3 character would be something like => "This is a text message with a long p"
i would like to receive something like :
"This is a text message with a long phrase" // instead of p , the entire word "phrase" or "This is a text message with a long " //if the number of characters is lower than 50% of the entire word like : phrase ( 6 characters ) => first 3 characters ( move the word to the next sentence ) and if is more than 3 display the entire word

so...the last result should be something like :

createtext(1 , "This is a text message with a long") // 34
createtext(2 , " phrase that i would like to split it") // 38
createtext(3 , "semi-equally in two or more sentences") // 37 characters


Is this hard to make or...should i start to move and split all my text manually?

Sorry for bad explication
Sorry for the bad English

Thanks
Alex

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Nov 2016 08:38
I would look at the CountStringTokens and GetStringToken commands.
Using AppGameKit V2 Tier 1
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 29th Nov 2016 10:47
Seems a bit complicated, can't you just set the maximum width of the text, then have it automatically roll onto the next line?

I'm sure that's how it works, AppGameKit will automatically continue your text onto the next line, using spaces as delimiters - but if you wanted to split a word then you will be on your own. I always say, the text handling in AppGameKit is great - compared to doing similar stuff in DBPro it's a different sport altogether. Be sure to look at all those text commands, there might be some you're not aware of but might find very useful.

Try it, just set the maximum width for a text entity and make the string really long, and see how it splits it up. When I want to enforce a new line, I just use the | character, then scan through the string, changing | for chr(10) before changing the text string.
The code is dark and full of errors
damothegreat
User Banned
Posted: 29th Nov 2016 14:52
newtext = "hello there is something the matter, I'm mad about AppGameKit, lol"

repeat


tw = screen width / font size pixel

if tw > len (newtext) then
// split
display first part of the string (but not if it exceeds the width of the screen

newtext the remaining text
endif


until tw < len(newtext)

Psudeo would be

- if the length of the string is more then the width of the screen, then

print the first
grab the remaining using MID function to the full length
repeat until the string is completely been used and printed to screen

Damo

Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
damothegreat
User Banned
Posted: 29th Nov 2016 15:34 Edited at: 29th Nov 2016 16:52
something like this




or do something fancier with it



Or



Anyway - hope it helps

Enjoy!!
Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Nov 2016 21:13
Quote: "Try it, just set the maximum width for a text entity and make the string really long, and see how it splits it up"


Damn, I just wrote a function for wrapping text when it reaches a set length, I didn't realise there was a command to do this!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-11-24 15:52:05
Your offset time is: 2024-11-24 15:52:05