Bueno tal cual como dice el título. Estoy haciendo un engine de Pokemon y encontré un código el cual funciona perfecto en GM8, pero al pasarlo al GMS me aparece este error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object DIALOGOS:
DoAdd :2: illegal array use
at gml_Object_DIALOGOS_StepNormalEvent_1 (line 4) - str+=string_char_at(texto[txtnum],i+1);
#####################################################################
Ya definí el arreglo de "texto" En el evento create.
///Create
texto = 0;
str='';
i=0;
txtnum = 0;
dem=0;
for(cantidad=0;cantidad<=20;cantidad+=1){
texto[cantidad]='';
}
texto[0]="1111111111111111";
texto[1]="2222222222222222222222222";
texto[2]="3333333333333333333333333";
texto[3]="_";
///Step
///Aquí sumamos a la cadena cada letra que venga detrás
if(i<string_length(texto[txtnum])){
if(dem=0){
str+=string_char_at(texto[txtnum],i+1);
i+=1;
}
if(dem>0)dem-=1;
//DEMORA un poco los caracteres si encuentra el signo '*';
if(string_char_at(texto[txtnum],i+1)='*'){
dem=20;
i+=1;
}
if(string_char_at(texto[txtnum],i+1)='·' and dem=0){
i=0;
str[0]='';
txtnum+=1;
}
}
if(texto[txtnum]<>'_'){
if(i=string_length(texto[txtnum]) and keyboard_check_pressed(ord('X'))){
i=0;
str[0]='';
txtnum+=1;
}
}else instance_destroy();
///Draw
///Pintamos el cuadro de diálogo.
draw_sprite(sprBox,0,view_xview+8,view_yview+168);
draw_set_color(c_black);
draw_text(view_xview+16,view_yview+174,string(str));
if (texto[txtnum+1] <> "_" && i = string_length(texto[txtnum])){
draw_sprite(Flecha,-1,view_xview+16+sprite_get_width(sprBox)-32,view_yview+218);
}
El problema está en el Step event porque quieres sumar algo a un array que no ha sido declarado. Me refiero a str[0]. Nos dará error porque no existía un valor previo para str[0].
Te paso el código corregido. (al solucionarlo encontré otro error cuando llegaba al final del diálogo, pues en el Draw event no encontraba el texto siguiente para compararlo con "_", la solución fue añadir otro texto[4] = "_" y ya se puede destruir el diálogo)
CREATE:
str = '';
i = 0;
txtnum = 0;
dem=0;
texto[0]="1111111111111111";
texto[1]="2222222222222222222222222";
texto[2]="3333333333333333333333333";
texto[3]="_";
texto[4]="_";
STEP:
/// Escribiendo el texto
if(i < string_length(texto[txtnum]))
{
if(dem == 0)
{
str += string_char_at(texto[txtnum],i+1);
i += 1;
}
if(dem > 0)
{
dem -= 1;
}
if(string_char_at(texto[txtnum],i+1) == '*')
{
dem = 20;
i+=1;
}
if(string_char_at(texto[txtnum],i+1)='·' and dem=0)
{
i=0;
str='';
txtnum+=1;
}
}
// Final de linea
if(texto[txtnum] <> '_'){
if(i == string_length(texto[txtnum]) and keyboard_check_pressed(ord('X'))){
i = 0;
str = '';
txtnum += 1;
}
}else instance_destroy();
DRAW:
///Pintamos el cuadro de diálogo.
draw_sprite(sprBox,0,view_xview+8,view_yview+168);
draw_set_color(c_black);
draw_text(view_xview+16,view_yview+174,string(str));
if (texto[txtnum+1] <> "_" && i = string_length(texto[txtnum])){
draw_sprite(Flecha,-1,view_xview+16+sprite_get_width(sprBox)-32,view_yview+218);
}