PDA

View Full Version : wraptext


xXziroXx
09-03-2006, 04:21 AM
How can I use wraptext/wraptext2 so that it DOESNT cut words in half when wrapping?

I used this in gs1:

wraptext 40,,#c;

.. and it didnt cut the text. However, when I converted it to gs2:

tokens = wraptext(40, "", player.chat);

.. it started cutting the text in half.

excaliber7388
09-03-2006, 08:06 AM
I'm sorry this post win't help you, but what does wraptext do?

smirt362
09-03-2006, 11:26 AM
I'm sorry this post win't help you, but what does wraptext do?

Instead of this:
Ebenezer unexpectedly bagged two tranquil aardvarks with his jiffy vacuum cleaner.

It would be something like this:
Ebenezer unexpectedly bagged
two tranquil aardvarks
with his jiffy vacuum cleaner.

It's like typing in Word. If your sentance/word gets too long then it moves part of it to the next line.

excaliber7388
09-03-2006, 05:43 PM
Instead of this:


It would be something like this:


It's like typing in Word. If your sentance/word gets too long then it moves part of it to the next line.
For what though?
Chat?

xXziroXx
09-03-2006, 05:49 PM
For what though?
Chat?

In this case, yes.

Tolnaftate2004
09-03-2006, 06:35 PM
font = "verdana";
style = "";
fontsize = $pref::graal::defaultfontsize/gettextheight(1,font,style);
tokens = wraptext2(40,fontsize," ",font @ "@" @ style @ "@" @ player.chat);
This will most accurately split at words and fit into your space. $pref::graal::defaultfontsize is a placeholder for the height in pixels of how tall you want the text to be. Change to your liking.

xXziroXx
09-04-2006, 12:19 AM
font = "verdana";
style = "";
fontsize = $pref::graal::defaultfontsize/gettextheight(1,font,style);
tokens = wraptext2(40,fontsize," ",font @ "@" @ style @ "@" @ player.chat);
This will most accurately split at words and fit into your space. $pref::graal::defaultfontsize is a placeholder for the height in pixels of how tall you want the text to be. Change to your liking.

I actually have never used $pref vars untill now.. however, now it doesnt wrap the text at all.

Tolnaftate2004
09-04-2006, 06:19 PM
Works for me. If you're using that code, you may want to give the variables a prefix. That could be why it's messing up.

xXziroXx
09-04-2006, 06:24 PM
Im scripting it in a gani, so I might aswell post the entire code here since it will be downloaded for everyone.


GANI0001

SCRIPT
function onCreated()
{
this.font = "Verdana";
this.style = "";
this.fontsize = $pref::graal::defaultfontsize / gettextheight(1, this.font, this.style);

setTimer(.05);
}

function onPlayerEnters() setTimer(.05);

function onTimeOut()
{
hideImgs(300, 309);
WordWrap();
for (i = 0; i < tokens.size(); i ++) {
showtext(300 + i, player.x + 1.6, player.y - 1.4 - 1*((tokens.size() - 1) - i), "Verdana", "cb", tokens[i]);
showtext(305 + i, player.x + 1.5, player.y - 1.5 - 1*((tokens.size() - 1) - i), "Verdana", "cb", tokens[i]);

changeimgcolors(300 + i, 0, 0, 0, 1);

changeimgzoom(300 + i, .7);
changeimgzoom(305 + i, .7);

changeimgvis(305 + i, 3);
}

if (client.busy == false) {
if (keydown2(16,true) || mousex in |player.x + .5, player.x + 2.5| && mousey in |player.y - 1, player.y + 3|) {
hideimgs(300, 309);
ShowNick();
ShowHUD();
for (i = 0; i < 4; i ++) changeimgzoom(300 + i, .7);
}
}

setTimer(.05);
}

function WordWrap()
{
//tokens = wraptext(40, " ", player.chat);
tokens = wraptext2(40, this.fontsize, " ", this.font @ "@" @ this.style @ "@" @ player.chat);
if (tokens.size() > 5) {
this.temp = NULL;
for (i = 0; i < 5; i ++) this.temp = this.temp SPC tokens[i];
this.text = this.temp.substring(0, this.temp.length() - 2) @ "..";
//tokens = wraptext(40, " ", player.chat);
tokens = wraptext2(40, this.fontsize, " ", this.font @ "@" @ this.style @ "@" @ player.chat);
}
}

function ShowNick()
{
showtext(300, player.x + 1.6, player.y + 3.4, "Verdana", "cb", player.nick.substring(0, player.guild.length() - 3));
showtext(301, player.x + 1.5, player.y + 3.3, "Verdana", "cb", player.nick.substring(0, player.guild.length() - 3));

showtext(302, player.x + 1.6, player.y + 4.4, "Verdana", "cb", player.guild);
showtext(303, player.x + 1.5, player.y + 4.3, "Verdana", "cb", player.guild);

changeimgcolors(300, 0, 0, 0, 1);
changeimgcolors(302, 0, 0, 0, 1);

changeimgvis(301, 3);
changeimgvis(303, 3);
}

function ShowHUD()
{
showimg(304, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2, player.y - 1.5 - (19/16)/2);
showimg(305, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2 + 6/16, player.y - 1.5 - (19/16)/2 + 4/16);

changeimgpart(304, 0, 0, 37, 13);
changeimgpart(305, 0, 14, 24/(player.fullhearts/player.hearts) + 1, 5);

changeimgvis(305, 3);
}
SCRIPTEND


EDIT: Fixed some values that I changed for testing.

Rapidwolve
09-04-2006, 09:49 PM
I'm sorry this post win't help you, but what does wraptext do?

It wraps text so it looks like a multi-line paragraph


Im scripting it in a gani

wtf

xXziroXx
09-05-2006, 05:52 PM
wtf

Yes?

And Tolnaftate2004 (or anyone else), if you can get the gani to work with the wraptext2 that you showed me, Id appriciate it. If not, I will have to make my own wraptext function.

xXziroXx
09-08-2006, 06:55 PM
Not anyone who can help?

xXziroXx
10-11-2006, 06:26 AM
*bumps* last attempt to get a wraptext expert, otherwise I will make my own function that will wrap the text.

Admins
10-13-2006, 02:11 AM
Added some description at http://wiki.graal.net/index.php/Creation/Dev/Script/Client#Graal_2D

You must specify the number of pixels (more than 40) and the zoom factor, which should match the zoom factor of the showimg you are using to display the text.