Advertisement
Guest User

Untitled

a guest
May 9th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @desc buffer_string_ini()
  2.  
  3. /*
  4.     You must initialize this script prior to using the other buffer_string_ functions
  5. */
  6.  
  7. globalvar _buffer_string_pos;
  8.  
  9. _buffer_string_pos = 0;
  10.  
  11. ------------------------------------------------------------------------------------------------------------------------------------------
  12.  
  13. /// @desc buffer_string_readln()
  14. /// @arg string
  15.  
  16. /*
  17.     Reads a line of text and returns it. Will skip to next line.
  18. */
  19.  
  20. gml_pragma("forceinline");
  21.  
  22. var str = string_delete(argument0,1,_buffer_string_pos);
  23. var pos = string_pos("\n",str);
  24. _buffer_string_pos += pos;
  25. str = string_copy(str,1,pos);
  26. str = string_replace(str,"
  27. ","");
  28. return str;
  29.  
  30. ------------------------------------------------------------------------------------------------------------------------------------------
  31.  
  32. /// @desc buffer_string_eof()
  33. /// @arg string
  34.  
  35. /*
  36.     Determines whether or not the buffer has reached the end of the text file.
  37. */
  38.  
  39. gml_pragma("forceinline");
  40.  
  41. return (_buffer_string_pos == string_length(argument0)-1);
  42.  
  43. ------------------------------------------------------------------------------------------------------------------------------------------
  44.  
  45. // THIS IS AN EXAMPLE BUT CAN BE USED AS CODE
  46.  
  47. file_open = buffer_load("items.txt");
  48. file_str = buffer_read(file_open,buffer_text);
  49. buffer_delete(file_open);
  50.  
  51. var str = "";
  52.  
  53. // Loop through each line of our text file until we reach the end
  54. while ( !buffer_string_eof(file_str) )
  55. {
  56.     str = buffer_string_readln(file_str);
  57.     show_debug_message(str);
  58. }
  59.  
  60. /*
  61. Once the string is stored in a variable "file_str" in this case, you may remove the buffer from memory and instead use file_str in all further buffer_string_* functions.
  62. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement