Dialogue Boxes and looping arrays

I

isador555

Guest
Hello ladies and gentlemen. I'm busy trying to make my first game with Gamemaker, and I could use a bit of help. I've created an object where my intent is to have that object be clickable, which will spawn a text box. When the text box gets clicked, it will cycle through several pages of dialogue, until it runs out of dialogue, at which point another click on the text box will make it disappear. When the player then clicks on the object again, it should spawn the text box again, starting on page 1.

Now, I'm not an experienced coder by any means, I'm mainly doing this with the help of a friend who knows how to do it, plus online tutorials, but those only go so far, and I've reached the point where I feel I've exhausted the resources I know about and can't move further without help.

This is the code i'm working with.

In the "create: event of this object, i put all of my text in an array:
alpha = true;
beta = true;

textbox1[0] = "text";
textbox1[1] = "text2";
textbox1[2] = "text3"
click_tracker = 0;

The alpha/beta variables are mainly there for the future, when I'd like to use those variables to make the same object pick one of several different arrays of text, but first, I need to get this to work properly.

Under a "left button" mouse event for this object, this is the code that spawns the text boxes.
if (alpha == true)
{
scr_text (textbox1[click_tracker], 0.5,64,64);
click_tracker++;
if (click_tracker > array_length_1d(textbox1)-1)
{
click_tracker=0;
}
}

Unfortunately, there's a few things wrong with it. First off, when I start my game and click the object, it spawns all the text boxes on top of each other in one go, instead of having one text box pop up per click. The text boxes are all removed at once if I click on them.
The second issue is that it doesn't scroll through new pages of text when I click on the text box. Instead, this code will (or rather, should, if it worked properly) create the first text box, which gets removed if the player clicks it, and if the player clicks the object again, it spawns text box two. Once it reaches the last text box, it resets and spawns the first text box again if the object is clicked.

So, would anyone be able to help me out with these two issues? To summarize, I need my text boxes to not all spawn on top of each other when my object is clicked, and if possible, I also want my text box to "scroll" through all available pages when clicked, rather than have to spawn a new text box every time I want to open the next page.
 
J

jackhigh24

Guest
have you tried it in the left pressed as the left button one will fire many times and the left pressed will only fire once and you have to let go and press again to fire it again
 
S

Snail Man

Guest
As mentioned, change the 'mouse left' event to 'left pressed': 'mouse loops fires for every step you hold the mouse button over the button, while 'left pressed' fires only once upon click.

To fix your second issue, you'll need to change scr_text, since I assume that makes a box pop up: to have it like you want, you need some function to modify the text in an existing pop up box, which isn't in the code you posted here
 
I

isador555

Guest
I did try to change it from a "mouse left" event to a "left pressed," but when I do that, the whole thing stops working altogether. No amount of clicking on the object will make anything spawn with that event.

Also, my apologies for not posting the scr_text. Here it is:
/// creating text ("text", speed, x,y)

txt = instance_create(argument2, argument3, obj_text)
with (txt)
{
padding = 16;
maxlength = view_wview[0];
text = argument0;
spd = argument1;
font = font_main;

text_length = string_length(text);
font_size =font_get_size(font);

draw_set_font(font_main);

text_width = string_width_ext(text,font_size+(font_size*2), maxlength);
text_height = string_height_ext(text,font_size+(font_size*2), maxlength);

boxwidth = text_width + (padding*2);
boxheight = text_height + (padding*2);
}
 
S

Snail Man

Guest
Alright, no idea about the first problem right now, but as for the second one, I'd modify scr_text to return a reference to the text box you just created (just add return(txt) at the end), that way you can refer to it later. Then in. The create event of your object, add textbox = noone;, and in the mouse event, make it so that IF !instance_exists(textbox) { textbox =scr_text(etc...) ;} else { textbox.text = etc...; }
Basically just making it so that if there's already a text box, update its text to the new text, otherwise, make a new one.
 
Top