Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @desc buffer_string_ini()
- /*
- You must initialize this script prior to using the other buffer_string_ functions
- */
- globalvar _buffer_string_pos;
- _buffer_string_pos = 0;
- ------------------------------------------------------------------------------------------------------------------------------------------
- /// @desc buffer_string_readln()
- /// @arg string
- /*
- Reads a line of text and returns it. Will skip to next line.
- */
- gml_pragma("forceinline");
- var str = string_delete(argument0,1,_buffer_string_pos);
- var pos = string_pos("\n",str);
- _buffer_string_pos += pos;
- str = string_copy(str,1,pos);
- str = string_replace(str,"
- ","");
- return str;
- ------------------------------------------------------------------------------------------------------------------------------------------
- /// @desc buffer_string_eof()
- /// @arg string
- /*
- Determines whether or not the buffer has reached the end of the text file.
- */
- gml_pragma("forceinline");
- return (_buffer_string_pos == string_length(argument0)-1);
- ------------------------------------------------------------------------------------------------------------------------------------------
- // THIS IS AN EXAMPLE BUT CAN BE USED AS CODE
- file_open = buffer_load("items.txt");
- file_str = buffer_read(file_open,buffer_text);
- buffer_delete(file_open);
- var str = "";
- // Loop through each line of our text file until we reach the end
- while ( !buffer_string_eof(file_str) )
- {
- str = buffer_string_readln(file_str);
- show_debug_message(str);
- }
- /*
- 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.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement