Misael644
Member
I am creating a function that serves as a textbox generator. The function works like this:
Note that in the middle of this text there are some numbers preceded by slashes. They serve to change the speed in the middle of the text.
Here's how the text formation part of this function works:
And here are the two alarms that participate in the function:
Note: I ended up calling the slashes "bars" in the code because of my English.
The typewriter effect part works ok. The problem is that when I need to use more than two numbers preceded by slashes to set the speed, not all numbers are erased correctly. Here is an example:
So, what am I doing wrong to make the code work correctly?
GML:
//the function
dialogue_create("Hello,/60 /03this is a test!","character",0,"left",3);
//description
/// dialogue_create(text,character,expression,pos,speed)
/// @arg text
/// @arg character
/// @arg expression
/// @arg pos
/// @arg speed
//arguments
var text = argument0;
var char = argument1;
var expr = argument2;
var pos = argument3;
var txtspeed = argument4;
Here's how the text formation part of this function works:
GML:
//le texto
global.DebugText = text;
if obj_game.TextInit == 1 {
global.count = 0;
obj_game.alarm[0] = 1;
obj_game.TextInit = 0;
};
var CharCheck = string_copy(text,global.count+1,1);
if CharCheck == "/" {
global.Bar = global.count+2;
global.Text2Remove = string_copy(text,global.count+1,3);
if obj_game.alarm[1] == -1 {obj_game.alarm[1] = 1};;
};
if obj_game.BarPosCount == 0 {
var text2 = text;
} else {
for(var i = 0; i < obj_game.BarPosCount; i += 1){
var text2 = string_replace_all(text,obj_game.TxtRemove[i],"");
};
};
if global.SpeedChange == false {
global.txtspeed = txtspeed;
} else {
global.txtspeed = real(string_copy(global.txt,global.Bar,2));
};
var textfinal = string_copy(text2,0,global.count);
global.txt = text;
global.txt2 = string_copy(text,0,string_length(text)-3*obj_game.BarPosCount);
draw_set_halign(fa_left);
draw_set_valign(fa_top);
draw_text_ext(40,((room_height/4)*3)+10,string(textfinal),20,room_width-80);
GML:
//Alarm 0
/// @desc Typewriter effect
global.count += 1;
if string_length(string_copy(global.txt2,0,global.count)) < string_length(global.txt2) {
alarm[0] = global.txtspeed;
};
//Alarm 1
/// @description Remove slashes
if BarPosCount > 0 {
if BarPos[BarPosCount-1] != global.Bar {
BarPos[BarPosCount] = global.Bar;
TxtRemove[BarPosCount] = global.Text2Remove;
BarPosCount += 1;
global.SpeedChange = !global.SpeedChange;
};
} else {
BarPos[BarPosCount] = global.Bar;
TxtRemove[BarPosCount] = global.Text2Remove;
BarPosCount += 1
global.SpeedChange = !global.SpeedChange;
};
The typewriter effect part works ok. The problem is that when I need to use more than two numbers preceded by slashes to set the speed, not all numbers are erased correctly. Here is an example:
So, what am I doing wrong to make the code work correctly?