GameMaker Issues with this code

R

rkraiem100

Guest
Hi, I'm trying to make a scrolling text box in gamemaker 2 and I found a good tutorial online but since the guy was using gamemaker 1.4 i'm running into a few small issues

In short this code creates a grey text box with scrolling text across the screen similar to most RPGs and VNs. The code is mostly working but when the text gets to the end of the line it pauses for half a second, adds a #, and tries to keep going but doesnt leave the text box.

I have a basic idea on how most of it works but I'm a total n00b so I cant fix it for my life... I ran it in Gamemaker 1.4 and it worked no problem so I know there are no syntax errors, there is probably some change they did to how u code in gamemaker 2 thats causing the issue

Also I want to get rid of the text box (or at least hide it, I just want the text itself) but if i remove the line that says "draw_roundrect_color(x,y,x+width,y+height,c_black,c_black,false);" then the whole screen is blank, any ideas?

Thanks


Code:

inside of an object:

Event: Create-

/// create some variables
width = 240;
height = 120;
padding = 8;

// keep track of the starting line
start = ds_list_create();
ds_list_add ( start,0);

// keep track of the last space and current position
count = 0;
last_space = 0;
line = 0;

// set the message
message = "this is a long message that is being written";
str = "";


Event: Game End-

/// destroy the ds list
ds_list_destroy( start );


Event: Draw
/// draw the string and the box
draw_set_alpha(.5);
draw_roundrect_color(x,y,x+width,y+height,c_black,c_black,false);
draw_set_alpha(1);

//set color to white
draw_set_color (c_white);

// are we past the width? insert a line break
// this has to be before getting the lase_space variable or it wont work right
if (string_width( str )> width-padding-padding ){
//remove the space and replace it with a line break
message = string_delete (message,last_space,1);
message = string_insert("#", message, last_space);
ds_list_add(start, last_space+1);
}

//make sure we have not reached the end of the mesage
if (count < string_length(message)){
//are we at a space? set the last space variable
if (string_char_at ( message, count) == " "){
last_space = count;
}

//increment the count
count+=1
}

//did we go past the bottom? move up a line
if (string_height (str) > height-padding){
line++;
}

//grab the string
str = string_copy(message, ds_list_find_value(start,line), count-ds_list_find_value(start, line));

//draw the text
draw_text(x+padding, y+padding, str);
 
Top