• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Text Wrap Issue

E

Eclectia

Guest
I'm working on textboxes right now. This is the base code for the obj_textbox event that gets called:

//
page = 0;
text = "";
xBuffer = 10;
yBuffer = 10;
boxWidth = sprite_get_width(Textbox);
boxHeight = string_height(text);
creator = noone;
name = noone;
draw_sprite(Textbox, 0, x, y);
draw_set_font(fnt_text);
draw_set_halign(fa_center);
draw_text (x+(boxWidth/2), y+yBuffer, name);
draw_set_halign(fa_left);
draw_text_ext (x+xBuffer, y+yBuffer, text[page], boxHeight, boxWidth);
if (keyboard_check_pressed(vk_space)){
if (page+1 < array_length_1d(text)){
page +=1
} else {
instance_destroy();
creator.alarm[1] = 1;
}
}
//
And this is the object, with the text:

//
Textbox = noone;
myName = "Deer Warden";
myText [0] = "Testing! Does this string length wrap to the next line?";
myText [1] = "Still testing!";
myText [2] = "Bazinga";
if (place_meeting(x, y, obj_player)){
if (keyboard_check_pressed(vk_space)){
if myTextbox == noone{
myTextbox = instance_create_layer(x, y, "text", obj_textbox);
myTextbox.text = myText;
myTextbox.creator = self;
myTextbox.name = myName;
}
}
} else {
if (myTextbox != noone){
instance_destroy(myTextbox);
myTextbox = noone;
}
}

//
This was working fine, wrapping and all until I implemented this change, because I wanted the textbox to pop up underneath the character rather than adjacent to them and was doing this manually:
//
draw_sprite(Textbox, 0, x-200, y+100);
draw_set_font(fnt_text);
draw_set_halign(fa_center);
draw_text (x-200+(boxWidth/2), y+90+yBuffer, name);
draw_set_halign(fa_left);
draw_text_ext (x-200+xBuffer, y+110+yBuffer, text[page], boxHeight, boxWidth-yBuffer);
//

For some reason, when I made the above changes to the base code, the wrapping doesn't work. I've tried a few variations on this code and nothing's worked. Any suggestions or advice would be appreciated - I hope I've described this alright.
 

jo-thijs

Member
I'm working on textboxes right now. This is the base code for the obj_textbox event that gets called:

//
page = 0;
text = "";
xBuffer = 10;
yBuffer = 10;
boxWidth = sprite_get_width(Textbox);
boxHeight = string_height(text);
creator = noone;
name = noone;
draw_sprite(Textbox, 0, x, y);
draw_set_font(fnt_text);
draw_set_halign(fa_center);
draw_text (x+(boxWidth/2), y+yBuffer, name);
draw_set_halign(fa_left);
draw_text_ext (x+xBuffer, y+yBuffer, text[page], boxHeight, boxWidth);
if (keyboard_check_pressed(vk_space)){
if (page+1 < array_length_1d(text)){
page +=1
} else {
instance_destroy();
creator.alarm[1] = 1;
}
}
//
And this is the object, with the text:

//
Textbox = noone;
myName = "Deer Warden";
myText [0] = "Testing! Does this string length wrap to the next line?";
myText [1] = "Still testing!";
myText [2] = "Bazinga";
if (place_meeting(x, y, obj_player)){
if (keyboard_check_pressed(vk_space)){
if myTextbox == noone{
myTextbox = instance_create_layer(x, y, "text", obj_textbox);
myTextbox.text = myText;
myTextbox.creator = self;
myTextbox.name = myName;
}
}
} else {
if (myTextbox != noone){
instance_destroy(myTextbox);
myTextbox = noone;
}
}

//
This was working fine, wrapping and all until I implemented this change, because I wanted the textbox to pop up underneath the character rather than adjacent to them and was doing this manually:
//
draw_sprite(Textbox, 0, x-200, y+100);
draw_set_font(fnt_text);
draw_set_halign(fa_center);
draw_text (x-200+(boxWidth/2), y+90+yBuffer, name);
draw_set_halign(fa_left);
draw_text_ext (x-200+xBuffer, y+110+yBuffer, text[page], boxHeight, boxWidth-yBuffer);
//

For some reason, when I made the above changes to the base code, the wrapping doesn't work. I've tried a few variations on this code and nothing's worked. Any suggestions or advice would be appreciated - I hope I've described this alright.
Please specify which code occurs in which event.
Also, please put code in code tags (when writing your post, there's an icon "Insert...", if you click it, you will get an option "Code", use that to insert code).

Also, can yyou specify what you mean with "wrapping doesn't work"?
Does your text not wrap at all when it should?
Is it wrapped at a wrong location?

It looks suspicious to me that you use boxWidth-yBuffer in this line:
Code:
draw_text_ext (x-200+xBuffer, y+110+yBuffer, text[page], boxHeight, boxWidth-yBuffer);
Although, with a value of 10 for yBuffer, I doubt that will be the cause of your issue.
 
E

Eclectia

Guest
I was typing up a reply to you, and I fixed it. I'm still not entirely sure how or why putting text between the blank "" in the Create event worked, but it did. Thank you, though!
 
Top