Jump to content

file functions


-.Paradox.-

Recommended Posts

Posted

Hey guys, I currently want to save player database using file functions, and for testing i used country as test, and actually it should write a line everytime a player login but actually it just replace it, This is my code.

Server:

if fileExists(country..".txt") then 
            local file = fileOpen(country..".txt") 
            fileWrite(file, "Name:"..name.." Serial:"..serial) 
            fileClose(file) 
        else 
            local file = fileCreate(country..".txt") 
            fileWrite(file, "Name:"..name.." Serial:"..serial) 
            fileClose(file) 
        end 

What i'm doing wrong?

Posted (edited)

Everything. Don't ever do that. Use a database management system. MTA supports the SQLite library and MySQL.

But just for the record, you should call fileSetPos to set the position where reads and writes will take place.

Edited by Guest
Posted
Everything. Don't ever do that. Use a database management system. MTA supports the SQLite library and MySQL.

Okay i won't use that, Would you please tell me what's wrong? Because i'd like to know what's wrong with it...

Posted

I dont quietly understand, Should it be like this?

  
local file = fileOpen(country..".txt") 
fileSetPos(file, 51)  
fileWrite(file, "Name:"..name.." Serial:"..serial) 
fileClose(file) 

Posted
local gSize = getFileSize(file) 
fileSetPos(file, gSize) 

This will be the last character of the file. You may want to use this to start drawing on a new line: \n

Posted
local gSize = getFileSize(file) 
fileSetPos(file, gSize) 

This will be the last character of the file. You may want to use this to start drawing on a new line: \n

fileGetSize(file) * 

It works, thanks, And there is one thing, How i can make it write a line everyplayer join in? Because currently it output like this

Name: Test Serial: 0123456789Name: Test Serial: 0123456789  

  • MTA Team
Posted

I also recomend using \r since if you read it with notepad it sometimes doesn't read the \n.

So, you would have to add \n\r.

Posted

Did you ever save it?

  
if fileExists(country..".txt") then 
            local file = fileOpen(country..".txt") 
            fileWrite(file, "Name:"..name.." Serial:"..serial) 
            fileSave(file) 
            fileClose(file) 
        end 
  

Posted
Did you ever save it?
  
if fileExists(country..".txt") then 
            local file = fileOpen(country..".txt") 
            fileWrite(file, "Name:"..name.." Serial:"..serial) 
            fileSave(file) 
            fileClose(file) 
        end 
  

fileSave doesnt exist

Posted
Did you ever save it?
  
if fileExists(country..".txt") then 
            local file = fileOpen(country..".txt") 
            fileWrite(file, "Name:"..name.." Serial:"..serial) 
            fileSave(file) 
            fileClose(file) 
        end 
  

Everything. Don't ever do that. Use a database management system. MTA supports the SQLite library and MySQL.

But just for the record, you should call fileSetPos to set the position where reads and writes will take place.

I'm not planning to save it anymore...

And your function doesn't exist

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...