• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Removing a line in a .txt file

dudeim

Member
Joined
Oct 5, 2007
Messages
121
Reaction score
9
Hey,

I want to remove a specific line from a file through the use of lua code, but I would have no idea how to do that.

for example I have a file like this:

Code:
val 1 = 10
val 2 = 11
val 3 = 12
val 4 = 13
val 5 = 14
etc..
note that the actual numbers don't matter

now how would I for example erase the line of val 3 so it would become like this:
Code:
val 1 = 10
val 2 = 11
val 4 = 13
val 5 = 14
etc..

So any idea's?

Edit:
Please note that I want a way to do this in lua, I know I can just backspace it etc.. I am not stupid:p

Thanks!
 
Last edited:
What do you want your script to do? It would probably be easier if you explained it, I think you are making this more complicated then it is. :p
 
I did explain it didn't I?

I have this in some text file from my server:
Code:
val 1 = 10
val 2 = 11
val 3 = 12
val 4 = 13
val 5 = 14

And I want this (val 3 = 12 to be removed) through lua scripting.
Code:
val 1 = 10
val 2 = 11
val 4 = 13
val 5 = 14
 
Im noob on lua but (in talkactions)-
Code:
function onSay(cid, words, param, channel)
	local inf = assert(io.open("data/talkactions/scripts/file.txt", "rw"), "Failed to open input file") -- what textfile to read
	local lines = ""
	while(true) do
	local line = inf:read("*line")
	if not line then break end
	if not string.find(line, "val 3 = 12", 1) then --if string not found
		lines = lines .. line .. "\n"
	end
	end
	inf:close()
	file = io.open("data/talkactions/scripts/file.txt", "w") -what textfile to write
	file:write(lines)
	file:close()
return true
end
 
Im noob on lua but (in talkactions)-
Code:
function onSay(cid, words, param, channel)
	local inf = assert(io.open("data/talkactions/scripts/file.txt", "rw"), "Failed to open input file") -- what textfile to read
	local lines = ""
	while(true) do
	local line = inf:read("*line")
	if not line then break end
	if not string.find(line, "val 3 = 12", 1) then --if string not found
		lines = lines .. line .. "\n"
	end
	end
	inf:close()
	file = io.open("data/talkactions/scripts/file.txt", "w") -what textfile to write
	file:write(lines)
	file:close()
return true
end

Thanks mate that works;)

dude open it with a text editor and just remove the line ?!
I kinda wanted it to happen like automaticly when some specific thing happens why else would I want to do it in lua lol...
 
Back
Top