Comunidad Game Maker

Ayuda => Desarrollo de Scripts => Mensaje iniciado por: deathmetal en Julio 31, 2013, 09:49:43 PM

Título: Script de diálogos GM5 no funciona en GM8(Solucionado)
Publicado por: deathmetal en Julio 31, 2013, 09:49:43 PM
Autores originales: Carl Larsson, aka Megabrain, Enigma or Teslago
Editado por: Meziku Asukana

Este escript utiliza la version de GM 5 :GM5:
Es de diálogos al estilo pokemon. Lo que hace es que primero dibujar el cuadro de diálogo en las coordenadas scr_dialog_x y scr_dialog_y. El sprite es del tamaño de toda la pantalla. Después dibuja el texto que le asignamos en el argument0 letra por letra. Si le texto es mayor a cierta cantidad (Que creo que es la variable splitamt) automaticamente lo dibuja después de que le des a la tecla S o A.

/*
Originally written by: Carl Larsson, aka Megabrain, Enigma or Teslagon.
Edited by: Meziku Asukana
You'll have to give credit to the creator, and I'd like it if you gave credit to me too.
EX: scr_dialog("TEXT", true, 0)
0=black text
1=white text
Check the sprite "spr_textbox" and you'll see them. Thats where this comes from.
And you can add more, although it'd kinda wreck a pokemon fan game. :D
Oh yeah, the "bg" is 240x161, so umm, yeah. You'll have to do just that.
*/
if argument1 = true
/*
Checks to see if dialog asked for is wanted.
Tip: You could use a global variable, set to true at first, allowing
the game to execute the dialog, then some event happens, and you don't
want it to be able to be read anymore. Like a postsign or something.
There's also a piece of script at the end of this that uses this variable.
*/
{
  keyboard_clear(vk_enter);
  /*
  The player might've clicked space/enter at the end of a dialog, and
  might be reading somemore, so this stops it from going on, so the
  player is allowed, humanely, to read it. lol
  */
  scr_dialog_x = view_x[0];
  //Sets View X variable, usually set to 0.
  scr_dialog_y = view_y[0]+view_height[0];
  /*
  Sets View Y variable and adds how tall it is, in this case *in a pokemon
  game*, it should be 160 or so. Game Screen: 240x160 WxH
  And both two lines of script above should end up to be the lower left corner.
  */
  draw_sprite(spr_textbox,0,scr_dialog_x,scr_dialog_y-160);
  /*
  So first, we have to draw the dialog box. Its up first, before the letters are drawn,
  b/c then, the letters will appear over the box. lol. *made it complicated probably*
  */
  scr_dialog_pause = false;
  //Added to fix a glitch that skipped pieces of text.
  scr_dialog_split = false;
  //Saves a variable to false. Will be explained further on.
  scr_dialog_texttype=argument2;
  //Determines which dialog text to use. Explained at the very top.
  scr_dialog_text = argument0;
  /*
  Saves the first thing typed in "scr_dialog(1, 2, 3)" into a variable.
  It SHOULD be text wrapped in QUOTES.
  */
  scr_dialog_pos  = 1;
  scr_dialog_disp  = '';
  scr_dialog_wait = 0;
  scr_dialog_finished = false;
  /*
  Above are miscallaneous, and are required for proper functionality. Ok?
  You pay the price for messing with it. :D
  */
  scr_dialog_splitamt = 55;
  /*
  Will be explained further on. *coexists with split var*
  Those set all the dialog variables.
  */
 
  if string_length(scr_dialog_text) > scr_dialog_splitamt
  {
  scr_dialog_text = string_copy(argument0,1,scr_dialog_splitamt);
  while string_char_at(scr_dialog_text,scr_dialog_splitamt)!=' '
  {
  if scr_dialog_splitamt < 70
  {
    scr_dialog_splitamt+=1;
  }
  scr_dialog_text = string_copy(argument0,1,scr_dialog_splitamt);
  if scr_dialog_splitamt = 70
  {
    break;
  }
  }
  scr_dialog_split = true;
  scr_dialog_resttext = string_copy(argument0,scr_dialog_splitamt,(string_length(argument0)-string_length(scr_dialog_text))+1);
  /*
  This explains both two lines of script above.
  If the text in the first argument is bigger than the splitamt value
  It'll save the split value to true, which happens around the end of this
  And save the rest of the text after the number of chars in splitamt.
  This is a handy function that lets the game itself seperate the text.
  */
  }
 
  //The rest of the script will explained later...I'm tired now and want to SCRIPT! :0
  scr_dialog_text = string_replace_all(scr_dialog_text,'#','');
  if string_length(scr_dialog_text) > 35
  {
    scr_dialog_lines = 1;
  }
  if string_length(scr_dialog_text) < 36
  {
    scr_dialog_lines = 0;
  }
  if string_char_at(scr_dialog_text,1) = ' '
  {
    scr_dialog_text = string_replace(scr_dialog_text,' ','');
  }
  for (scr_dialog_li=1;scr_dialog_li<=scr_dialog_lines;scr_dialog_li+=1)
  {
    scr_dialog_add_13 = 0;
      while string_char_at(scr_dialog_text,(35*scr_dialog_li)-scr_dialog_add_13) != ' ' or scr_dialog_add_13 < 7
      {
        if string_char_at(scr_dialog_text,(35*scr_dialog_li)-scr_dialog_add_13) = ' ' or scr_dialog_add_13 > 7
        {
          break;
        }
        scr_dialog_add_13 += 1;
      }
    scr_dialog_mark_13[scr_dialog_li] = (35*scr_dialog_li)-scr_dialog_add_13;
    scr_dialog_text = string_insert(" #",scr_dialog_text,(35*scr_dialog_li)-scr_dialog_add_13);
  } 
  scr_dialog_text = string_replace_all(scr_dialog_text,'# ','#');
}


if scr_dialog_finished = false
{
  scr_dialog_disp = string_copy(scr_dialog_text,1,scr_dialog_pos);
  if keyboard_check(global.ctrl_cancel)=true
  {
    scr_dialog_pos += 3;
  }
  else
  {
    scr_dialog_pos += 1;
  }
  /*
  Explains ALL nine LINES above, including the {'s -_-. This gives it the effect as typing it, letter by letter.
  That +=1 there makes it one letter by letter, if you change it to 2, it'll do 2 by 2
  */
  if scr_dialog_texttype=1
  {
    draw_text_sprite(scr_dialog_x+16,scr_dialog_y-38,scr_dialog_disp,16,999,spr_textwhite,'!',1);
  }
  else
  {
    if scr_dialog_texttype=0
    {
      draw_text_sprite(scr_dialog_x+16,scr_dialog_y-38,scr_dialog_disp,16,999,spr_textblack,'!',1);
    }
  }
  screen_refresh();
  if scr_dialog_text = scr_dialog_disp
  {
    scr_dialog_finished = true;
  }
}

if keyboard_check(vk_space)
{
  keyboard_clear(vk_enter);
  screen_refresh();
}

if scr_dialog_finished = true
{
  screen_refresh();
  io_clear();
  if scr_dialog_pause = false
  {
    do
    {
      keyboard_wait();
      if keyboard_lastkey=global.ctrl_trigger
      {
        scr_dialog_wait=1;
      }
      else
      {
        if keyboard_lastkey=vk_f12
        {
          event_perform_object(type_bts,ev_keyrelease,vk_f12);
          io_clear();
        }
        else
        {
          io_clear();
        }
      }
    }
    until (scr_dialog_wait=1)
  }
  sound_play(sfx_dialog)
  //You know, the pokemon games have that sound effect. Its removable.
  screen_redraw();
  io_clear();
  if scr_dialog_split = true
  /*
  So yeah. That split var from before. Let me explain it now.
  The splitamt var is set to a number of how many chars should be able
  to fit in the dialog box. This split variable sees if the dialog is over
  the splitamt. It is set to true if it is over splitamt, else, the
  the following script doesn't happen.
  */
  {
    scr_dialog(scr_dialog_resttext,true,scr_dialog_texttype);
    /*
    So then, the text saved from before is now shown, and loops
    if it continously is bigger than the splitamt value.
    */
  }
}
else
{
  sleep(50);
  //Sets some time between drawing letters.
  scr_dialog(argument0,false,scr_dialog_texttype);
}



PERO yo lo quiero usar en GM 8  :GM8: por lo que traté de adaptarlo y este fue el resultado.
Las adaptaciones que hice fue mover las coordenadas para ajustarlas a mi view, así como eliminar la funcion de draw_tex_sprite por otro script que lo único que hace es dibujar texto con sprite.

Argument0= //Texto a dibujar
Argument1= //No tengo ni idea
Argument2= //El color del texto 0=rojo, 1=blanco


//
//Originally written by: Carl Larsson, aka Megabrain, Enigma or Teslagon.
//Edited by: Meziku Asukana
//You'll have to give credit to the creator, and I'd like it if you gave credit to me too.
//EX: scr_dialog("TEXT", true, 0)
//0=black text
//1=white text

if argument1 = true

//Checks to see if dialog asked for is wanted.
//Tip: You could use a global variable, set to true at first, allowing
//the game to execute the dialog, then some event happens, and you don't
//want it to be able to be read anymore. Like a postsign or something.
//There's also a piece of script at the end of this that uses this variable.

{
  keyboard_clear(vk_enter);
  /*
  The player might've clicked space/enter at the end of a dialog, and
  might be reading somemore, so this stops it from going on, so the
  player is allowed, humanely, to read it. lol
  */
  scr_dialog_x = view_xview;
  //Sets View X variable, usually set to 0.
  scr_dialog_y = view_yview+100;
  /*
  Sets View Y variable and adds how tall it is, in this case *in a pokemon
  game*, it should be 160 or so. Game Screen: 240x160 WxH
  And both two lines of script above should end up to be the lower left corner.
  */
  draw_sprite(dialog_box_spr,0,scr_dialog_x,scr_dialog_y);
  /*
  So first, we have to draw the dialog box. Its up first, before the letters are drawn,
  b/c then, the letters will appear over the box. lol. *made it complicated probably*
  */
  scr_dialog_pause = false;
  //Added to fix a glitch that skipped pieces of text.
  scr_dialog_split = false;
  //Saves a variable to false. Will be explained further on.
  scr_dialog_texttype=argument2;
  //Determines which dialog text to use. Explained at the very top.
  scr_dialog_text = argument0;
  /*
  Saves the first thing typed in "scr_dialog(1, 2, 3)" into a variable.
  It SHOULD be text wrapped in QUOTES.
  */
  scr_dialog_pos  = 1;
  scr_dialog_disp  = '';
  scr_dialog_wait = 0;
  scr_dialog_finished = false;
  /*
  Above are miscallaneous, and are required for proper functionality. Ok?
  You pay the price for messing with it. :D
  */
  scr_dialog_splitamt = 55;
  /*
  Will be explained further on. *coexists with split var*
  Those set all the dialog variables.
  */
 
  if string_length(scr_dialog_text) > scr_dialog_splitamt
  {
  scr_dialog_text = string_copy(argument0,1,scr_dialog_splitamt);
  while string_char_at(scr_dialog_text,scr_dialog_splitamt)!=' '
  {
  if scr_dialog_splitamt < 70
  {
    scr_dialog_splitamt+=1;
  }
  scr_dialog_text = string_copy(argument0,1,scr_dialog_splitamt);
  if scr_dialog_splitamt = 70
  {
    break;
  }
  }
  scr_dialog_split = true;
  scr_dialog_resttext = string_copy(argument0,scr_dialog_splitamt,(string_length(argument0)-string_length(scr_dialog_text))+1);
  /*
  This explains both two lines of script above.
  If the text in the first argument is bigger than the splitamt value
  It'll save the split value to true, which happens around the end of this
  And save the rest of the text after the number of chars in splitamt.
  This is a handy function that lets the game itself seperate the text.
  */
  }
 
  //The rest of the script will explained later...I'm tired now and want to SCRIPT! :0
  scr_dialog_text = string_replace_all(scr_dialog_text,'#','');
  if string_length(scr_dialog_text) > 35
  {
    scr_dialog_lines = 1;
  }
  if string_length(scr_dialog_text) < 36
  {
    scr_dialog_lines = 0;
  }
  if string_char_at(scr_dialog_text,1) = ' '
  {
    scr_dialog_text = string_replace(scr_dialog_text,' ','');
  }
  for (scr_dialog_li=1;scr_dialog_li<=scr_dialog_lines;scr_dialog_li+=1)
  {
    scr_dialog_add_13 = 0;
      while string_char_at(scr_dialog_text,(35*scr_dialog_li)-scr_dialog_add_13) != ' ' or scr_dialog_add_13 < 7
      {
        if string_char_at(scr_dialog_text,(35*scr_dialog_li)-scr_dialog_add_13) = ' ' or scr_dialog_add_13 > 7
        {
          break;
        }
        scr_dialog_add_13 += 1;
      }
    scr_dialog_mark_13[scr_dialog_li] = (35*scr_dialog_li)-scr_dialog_add_13;
    scr_dialog_text = string_insert(" #",scr_dialog_text,(35*scr_dialog_li)-scr_dialog_add_13);
  } 
  scr_dialog_text = string_replace_all(scr_dialog_text,'# ','#');
}


if scr_dialog_finished = false
{
  scr_dialog_disp = string_copy(scr_dialog_text,1,scr_dialog_pos);
  if keyboard_check(vk_space)=true
  {
    scr_dialog_pos += 3;
  }
  else
  {
    scr_dialog_pos += 1;
  }
  /*
  Explains ALL nine LINES above, including the {'s -_-. This gives it the effect as typing it, letter by letter.
  That +=1 there makes it one letter by letter, if you change it to 2, it'll do 2 by 2
  */
  if scr_dialog_texttype=1
  {
  draw_set_color(c_white)
    dialogo_script(scr_dialog_disp,scr_dialog_x+8,scr_dialog_y+4);
  }
  else
  {
    if scr_dialog_texttype=0
    {
    draw_set_color(c_red)
      dialogo_script(scr_dialog_disp,scr_dialog_x+8,scr_dialog_y+4);
    }
  }
  screen_refresh();
  if scr_dialog_text = scr_dialog_disp
  {
    scr_dialog_finished = true;
  }
}



if scr_dialog_finished = true
{
  screen_refresh();
  io_clear();
  if scr_dialog_pause = false
  {
    do
    {
      keyboard_wait();
      if keyboard_lastkey=vk_space
      {
        scr_dialog_wait=1;
      }
      else
      {
        if keyboard_lastkey=vk_f12
        {
          event_perform_object(type_bts,ev_keyrelease,vk_f12);
          io_clear();
        }
        else
        {
          io_clear();
        }
      }
    }
    until (scr_dialog_wait=1)
  }
  //sound_play(sfx_dialog)
  //You know, the pokemon games have that sound effect. Its removable.
  screen_redraw();
  io_clear();
  if scr_dialog_split = true
  /*
  So yeah. That split var from before. Let me explain it now.
  The splitamt var is set to a number of how many chars should be able
  to fit in the dialog box. This split variable sees if the dialog is over
  the splitamt. It is set to true if it is over splitamt, else, the
  the following script doesn't happen.
  */
  {
    scr_dialog(scr_dialog_resttext,true,scr_dialog_texttype);
    /*
    So then, the text saved from before is now shown, and loops
    if it continously is bigger than the splitamt value.
    */
  }
}
else
{
  sleep(50);
  //Sets some time between drawing letters.
  scr_dialog(argument0,false,scr_dialog_texttype);
}


El problema es que.... el texto nunca se dibuja en las coordenadas que le puse. Se dibuja donde se le da la gana. Tanto el texto como el cuadro de diálogo. Imagino que habrá alguna variable que modifique las coordenadas... pero no la encuentro. Alguien ve el problema? :C

EDIT

Cuando quieres dibujar algo fuera del evento draw, además de refrescar la pantalla debes usar las funciones de view_xport y view_yport, en lugar de view_xview y view_yview...