Legacy GM [SOLVED] Displaying text dynamically using a for loop and string_height_ext?

Dr_Nomz

Member
I'm trying to make a dynamic text system where the script below will display a certain line of text based on what's in the list and what position it's in.

But to make it work right i need to have it somehow know the height of the previous string, based on what the last list entry is. Any ideas?
Code:
  for(var test1 = 0; test1 < ds_list_size(global.quest_update_TEST); test1++){
  test_str[test1] = string_height_ext(ds_list_find_value(global.quest_update_TEST,test1),20,474);
 
  //Use the find_value function to see if the list has a certain value
  //ANYWHERE in the list, and if so, it'll display it.
  if ds_list_find_value(global.quest_update_TEST,test1) == "ez"{
    draw_text_outline(xx+188,yy+162+(test1*number)+test_str[test1],
    "It works REALLY well. :D asfasdfs gfas ggs a sf af sdasd fda ",
    2,c_black,4,20,474);
  }
  if ds_list_find_value(global.quest_update_TEST,test1) == "yes"{
    draw_text_outline(xx+188,yy+162+(test1*number)+test_str[test1],
    "It works. dddddddddddddddddddddddddddddddddddddddd",
    2,c_black,4,20,474);
  }
  if ds_list_find_value(global.quest_update_TEST,test1) == "hi"{
    draw_text_outline(xx+188,yy+162+(test1*number)+test_str[test1],
    "YESSSSSSSSSSSS ssssssssssssssssssssssssssssssssssssssssssss",
    2,c_black,4,20,474);
  }
  }
 

CloseRange

Member
let me try my hand at this ig:

Code:
 var current_height = yy+162; // this is where the top of the list is
 for(var test1 = 0; test1 < ds_list_size(global.quest_update_TEST); test1++){
  var text = "";
  // i use a switch statment because it's a bit more clear than chaining if statments
  // persanolly i'd include the text's in some sort of file or ds_list and get them that way but this is fine
  switch(ds_list_find_value(global.quest_update_TEST, test1) {
   case "ez": 
    text = "It works REALLY well. :D asfasdfs gfas ggs a sf af sdasd fda ";
    break;
   case "yes":
    text = "It works. dddddddddddddddddddddddddddddddddddddddd";
    break;
   case "hi":
    text = "YESSSSSSSSSSSS ssssssssssssssssssssssssssssssssssssssssssss";
    break;
  }
  current_height += string_height_ext(text, 20, 474); // increase the height position
  var dx = xx+188;
  var dy = current_height;
  draw_text_outline(dx, dy, text, 2, c_black, 4, 20, 474);
 }
 

Dr_Nomz

Member
DUDE thanks, that's 💩💩💩💩ing perfect for what I need. :D

A couple things though, first you forgot a bracket ) at the end of the first line lol. ALSO, IMPORTANT:
Code:
  var dx = xx+188;
  var dy = current_height;
  draw_text_outline(dx, dy+(1*number)+test1, text, 2, c_black, 4, 20, 474);
  current_height += string_height_ext(text, 20, 474); // increase the height position
The way you had it before, it would automatically update the height WHILE the text was being drawn, so it would reference it's own height, rather than that of the previously added text. I fixed it so it doesn't do that now, just wanted to let you know. :D
 

CloseRange

Member
DUDE thanks, that's ****ing perfect for what I need. :D

A couple things though, first you forgot a bracket ) at the end of the first line lol. ALSO, IMPORTANT:
Code:
  var dx = xx+188;
  var dy = current_height;
  draw_text_outline(dx, dy+(1*number)+test1, text, 2, c_black, 4, 20, 474);
  current_height += string_height_ext(text, 20, 474); // increase the height position
The way you had it before, it would automatically update the height WHILE the text was being drawn, so it would reference it's own height, rather than that of the previously added text. I fixed it so it doesn't do that now, just wanted to let you know. :D
not too surprised i had a couple of mistakes thats what i get for not testing it and just writing it directly in the forums. glad it helped though!
 
Top