• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Using Txt file: Write to Buffer, Read String from Line, Send to Var to Display Character Dialog

How do I put a txt file into a buffer then read specific lines from it?

(eg. like how file_text_open_read() and file_text_readln() do without a buffer)

I need to read strings with both numbers, and letters then feed it to a variable for display. Also I want to be able to add lines together in the variable so as to get a line range if needed. I know how to do this with the above mentioned commands, but not using buffers.
 
Have you read the manual on this subject? It pretty much explains how buffers work and gives examples of use. http://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/buffers/index.html
I'm not asking for an overview, I'm asking for application. Just because there's a ton of complicated info there doesn't mean I know what would apply in my specific situation. What's the equivalent of what I'm asking if I use a buffer to do it instead of find_text_open_read(), and file_text_read_ln() each time I want to grab some dialog? Yes I did check the manual first, seeing info and knowing how to apply it aren't the same. How do I get a specific line from the txt file that I load into the buffer?
 
Last edited:

sylvain_l

Member
why do you want to use buffer instead of an array or data structure (like a ds_list) ? what the advantage of using buffer over other solution in your specific case ? (and does it worth the trouble, because buffers are more complex to handle as you must do it all, which can be in return an advantage, as it give you full control that's why Yal consider that as the best solution, cause that way you seek the position of text you want and read the bytes you need. job done.)

I'm going to be rude perhaps, but rule of thumb: if you are not able to use buffer just RTFM, that mean you are not ready to use buffer.
seriously Nocturne give you the reference manual; not an overview; it's the reference of each function, what they are and how to use them !

p.s.
if you are using only ascii, the short answer is just directly load the file into buffer(there is a function that handle that), and then use it (ascii char are just the size of 1 byte = 8bits).
very basic example in an object

create event:
Code:
hBuf = buffer_load("dummy_included_file.txt");

// here I fetch the wall content as text, you'll have to refine that part creating a script function for example
// to fetch the part of text you only want
// (and yeh, that the part where you get in charge because you have full control, that also mean you have
// to code the thing so it happen the way you want; nobody precoded all the function for all the thing that
// all users want to do. that what buffer are about too: DIY)
text = buffer_read(hBuf, buffer_text);
and in draw event
Code:
draw_text(0,0,text);
edit:
should add the clean up event to avoid any memory leak
Code:
buffer_delete(hBuf);
 
Last edited:
Top