1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

String.GMatch

Discussion in 'Development' started by Vortix, Jul 29, 2014.

  1. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    I'm trying to read the lines of a file and separate them by their lines, however I can't seem to get it to work. Using:
    string.gmatch("\r\n", file.Read("file.txt", "DATA"));
    I come up with an error saying nil value on the second argument, this makes me think the file is not being read (As in wrong directory). I have the path data/file.txt which I have tried moving to the commands/ directory (where the file where the string.gmatch command is located) and the same directory as the plugin.ini, as a taken example from Atebite's random name setter, however mine doesn't seem to be working.
    Any suggestions would be appreciated.
     
  2. duck

    duck Phant0m Legend

    Use string.sub or string.gsub

    gsub is what you should use for this, but you should look into string.sub as well.
     
  3. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Thanks for your reply.
    I'm attempting to separate the strings by the new lines rather than replacing the new lines.
    I've used: local cpdata = string.gmatch("\r\n", file.Read("cpdata.txt", "DATA"));
    And am trying to pass the data into the variable cpdata so I can use it like so later on: name = cpdata[1]. I've taken example from Atebite's random name setter and everything seems to be in order?
    If you understood my meaning and the answer you provided was still correct then how might I go about achieving what I needed using it?
    Any further advice?
     
  4. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Nevermind, I've fixed it and was being an idiot.

    EDIT: I appear to be getting a new error now, on attempting:
    name = cpdata[1]
    I get: "Attempting to index local 'cpdata' (a function value)" As an error.

    I've managed to fix it, another stupid mistake.
     

Previous Readers (Total: 0)