Simple Text Problem

C

Cossie

Guest
Hiya! <3

Still bit new to game maker, little slow.


Followed Shaun Spaldings platformer video on Signposts.

Everything is working just as it should. I'm using the string variable trick to make it easier to change later on.

The only question I have is I am unsure how to make multiple pages of dialogue/text appear using his system. How can I change his code for longer dialogue/multiple pages?


Text Object Code:

Create Event:

Code:
spd = 0.25;
letters = 0;
text = "test string!";
length = string_length(text);
text_current = "";
w = 0;
h = 0;
border = 10;
Step Event:
Code:
letters += spd;
text_current = string_copy(text,1,floor(letters));

draw_set_font(fText);
if (h == 0) h = string_height(text);
w = string_width(text_current);

//Destroy when done
if (letters >= length) && (keyboard_check_pressed(vk_anykey))
{
    instance_destroy();
    with (oCamera) follow = oHannah;
}

Draw Event:

Code:
var halfw = w * 0.5;

//Draw The Box
draw_set_colour(c_black);
draw_set_alpha(0.5);
draw_roundrect_ext(x-halfw-border,y-h-(border*2),x+halfw+border,y,15,15,false);
draw_sprite(sMarker,0,x,y);
draw_set_alpha(1);

//Draw text
DrawSetText(c_white, fText, fa_center, fa_top);
draw_text(x,y-h-border,text_current);
 

obscene

Member
It's a tricky thing actually. Will be tough if you're new. Here's just some bullet points to consider...

  • You need to decide a way to break your text into multiple strings. For instance, you use a character like # to indicate a new page.
  • Your code will need to loop through your string looking for that character and copy each section into an array of strings (text[0],text[1],text[2],etc). So if you don't already know how to use arrays as well as functions like string_copy(), string_pos() you'll need to get familiar with them.
  • You'll need to track how many strings were created so you know how many pages will be displayed. Then each time you display text, you'll track what page you are on. (1 or 1, 1 of 2, 2 of 2) etc.
  • When you are on the last page, pressing a button closes the text box. When you have another page to display, pressing a button will change the page to the next page and reset variables like letters so your typewriter text will start again as well as h and w so it will resize again.

It might be difficult, but if you can work through each issue one a time this is actually a great exercise to learn from.
 
C

Cossie

Guest
Thank you so much! <3
Last, my only question is, do you have any resources where I can learn how these functions work and how to properly use them? Thanks again. <3
 

FrostyCat

Redemption Seeker
The Manual tells you how all this works. The first 14 articles tell you how the language works, and the Index tab lets you look up any built-in keyword, variable or function.

The biggest problem on the Q&A section is people blindly following tutorials without understanding or looking up basic syntax elements and built-in functions.
 
Top