1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

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

Discussion in 'Programming' started by 2d_warrior, Jul 20, 2017.

  1. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    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.
     
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,046
  3. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    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: Jul 20, 2017
  4. sylvain_l

    sylvain_l Member

    Joined:
    Sep 18, 2016
    Posts:
    705
    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: Jul 20, 2017

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice