Jump to content
  • Advertisement
Sign in to follow this  
PGSCreativeDirector

Unity String:gmatch in lua problem

This topic is 2394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font="Lucida Console"]could someone tell me how to fix this i don't see the problem ?[/font]

[font="Lucida Console"]This is my problem:[/font]

[font="Lucida Console"]I can't after every gmatch occurrence write to a textfile for every occurence of .txt [/font]


[font="Lucida Console"]What are you using?[/font]
[font="Lucida Console"]i'm using gmatch to find .txt, which .txt is in a textfile eg ( " what i mean is a textfile of it contents"). [/font]

[font="Lucida Console"]Then writing to another textfile for every occurrence of .txt [/font][font="Lucida Console"] this would output like this eg( textfile1,textfile2,textfile3 and so on). [/font]


Heres My Code


require "lfs"


file = io.open("ListingDirectoryList.txt","w")

input = io.open("AmountofTextFiles.txt","w")

for content in lfs.dir ("content") do file:write(content, " ")
end



file:close()




for line in io.lines("ListingDirectoryList.txt") do if line:gmatch(".txt","%a+") then do input:write("textfile", +1)
end
end
end






input:close()


Could anyone tell me how to fix this


I took a look at the lua reference and lua programming and couldn't find any more information then the functions explanations themselves and it just really annoying for me so im asking the community

Share this post


Link to post
Share on other sites
Advertisement
I'm really not sure if I understand what you're asking, but you probably want something like this:



-- Assuming input file is just a list of file names + extensions, with only one per line.

local input = io.open("test.txt", "w")

local output = ""

for line in input:lines() do
local textfile = line:match("(%w+)%.txt")

if textfile then
output = output .. textfile .. "\n"
end
end

input:close()

print(output)



I leave outputting things in the exact way you want for you to do.

Note that gmatch is for iterating over a string, but you probably want to use match instead if you just have one text file per line in the input. Note that there are two ways to call the string.gmatch function: string.gmatch(input_str, pattern) and input_str:gmatch(pattern). You seem to be mixing these in ways that do not make sense. I would also be surprised if just putting +1 as a parameter to output does what you want.

Share this post


Link to post
Share on other sites

I'm really not sure if I understand what you're asking, but you probably want something like this:

[source lang="lua"]

-- Assuming input file is just a list of file names + extensions, with only one per line.

local input = io.open("test.txt", w)

local output = ""

for line in input:lines() do
local textfile = line:match("(%w+)%.txt")

if textfile then
output = output .. textfile .. "\n"
end
end

input:close()

print(output)

[/source]

I leave outputting things in the exact way you want for you to do.

Note that gmatch is for iterating over a string, but you probably want to use match instead if you just have one text file per line in the input. Note that there are two ways to call the string.gmatch function: string.gmatch(input_str, pattern) and input_str:gmatch(pattern). You seem to be mixing these in ways that do not make sense. I would also be surprised if just putting +1 as a parameter to output does what you want.





Could you leave my code as is and do the same thing as much as possible so i can understand what you written better your using some terms im not aware of at this moment in time soz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Armaan Gupta
      Hey There,
      I am a developer and Im working on a blockchain based infinite runner type game. Right now, I am working on releasing the beta version with a couple other game developers, but would love to expand the team and have other talented and bright people contributing. The game portion of the project isnt very complicated, and wouldnt require anyone to pull thier hair out for it.
      If you are interested in joining a project, interested in the idea, or would like some more information, please don't hesitate to ask either by commenting, discord (username: Guppy#7625), or by email (armaangupta01@gmail.com).
      Thank you!
    • By Joydeep Mani
      I am trying to build a particle system for unity based on "Destiny particle architecture " released in Siggraph.
      I encounter a problem in trying to understand how they iterated this:

      Converted to spline function and the result is

      i wanted to know how did they converted the function in the editor to represent the graph ??
       
    • By Xerath Dragons
      This is my first experiment use for create my original character little cute dragon chibi use zbrush and blender and use unity3d assest free for enviroment scene you have feedback?
       


    • By Aryndon
      Project Redemption is an semi-fantasy RPG with a linear story and an elaborate combat system.
      We are building in Unity and are currently looking animators and artists.
      What we are looking for
      -Someone who is okay with split revenue/profits when finished
      -Collaborate with others in the team. Do you have an idea/thought on what should be included? Tell us!
      -Someone who wants to work with people that are passionate about this project
      If you are interested. Please message me and I will get back to you as soon as possible! Or add me on Discord AJ#6664
    • By Aggrojag
      Hello!
      I'm working on a game that is a narrative driven dark comedy with some small aspects of platforming and puzzle solving. The project is rather small as well. It touches on topics such as suicide, mental illness, family, corruption, free-will, and redemption.
      This project is exercise in polish, this means some experimentation will be needed along with some reworking of assets as they're provided.
      This will be a revshare model.
      First, I'm looking for a 2D sprite artist, not pixelated, that can compliment the style of the attached images, and be similar to the temporary character.
      We are looking to bring on a SFX designer at this time. Full list of required SFX will be available upon request, as well as a build with all elements related to sound implemented in some form (many SFXs pulled from the web for now). Will likely require some field recording, and some pretty strange SFX for when things get weird. I imagine a good portion of these will be quite fun to create.
      Lastly, I'm looking for a male voice actor, English should be your primary language. There will be at minimum two characters that will need to be brought to life through vocals. The first voice is similar to Marvin from Hitchhiker's Guide to the Galaxy. A reference for the second voice would be a mix of Ren (Ren & Stimpy), and Android 21 (DragonBallFighterZ). Due to formatting, I'm not including YouTube links in the post, sorry.
       
      WIP Scene with our custom shaders attached (platforms are lazily placed, as this was an asset test):

      A scene with dynamic lighting and temp character:

       
      Unshaded asset:

      If you made it to the bottom, thank you, and I look forward to hearing from you.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!