1x1 Posted December 24, 2022 Share Posted December 24, 2022 Hello, so i wanna make a lua script that write a file and I'll use another lua script to read this file if is true or not. So i will create a file like this 1 - False 2 - False 3 - False So i'll ask Write.lua to change 1 into True. Then Read.lua Will check if 1 is true or not. Same goes to 2 and 3. Please help me :) Link to comment Share on other sites More sharing options...
MAARS Posted December 24, 2022 Share Posted December 24, 2022 I think putting the line number is a bad idea cause it require you to do extra parsing when you will read the data in it local function appendFile(fileName, data) local file, err = io.open(fileName, "a+") file:write(tostring(data) .. "\n") file:close() end local function readLine(fileName, lineNumber) local data pcall(function() local f = io.lines(fileName) if lineNumber == 1 then data = f() return end while true do local line = f() if not line then break end lineNumber = lineNumber - 1 if lineNumber == 0 then data = line break end end end) return data end -- write to files ( file name, data to write ) appendFile("test.txt", true) appendFile("test.txt", true) appendFile("test.txt", false) appendFile("test.txt", true) -- read from files ( file name, line numberic ) print(readLine("test.txt", 1)) print(readLine("test.txt", 2)) print(readLine("test.txt", 3)) print(readLine("test.txt", 4)) Link to comment Share on other sites More sharing options...
HEROGAMEOfficial Posted December 24, 2022 Share Posted December 24, 2022 local file = io.open(your_file, 'r') file = file and not print('File reading succesfull') and gg.toast('File reading succesfull') and file:read('*a') or gg.toast('File reading succesfull') Link to comment Share on other sites More sharing options...
Question
1x1
Hello, so i wanna make a lua script that write a file and I'll use another lua script to read this file if is true or not.
So i will create a file like this
So i'll ask Write.lua to change 1 into True. Then Read.lua Will check if 1 is true or not.
Same goes to 2 and 3.
Please help me :)
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.