Jump to content

Help, saving element data.


Recommended Posts

Hello, I'm having a problem trying to save an element data into a .ini file, here's my code

    local playerName = getPlayerName( source ) 
    local levelAdmin = getElementData(source,"Admin") 
    local stringName = string.format("Users/%s.ini",playerName) 
    local stringAdmin = string.format("Admin: %i\n",levelAdmin) 
    fileOpen(stringName) 
    fileWrite(stringName,stringAdmin) 
    fileClose(stringName) 

But when I disconnect, I get 2 warnings and nothing saves: Bad 'file' pointer @ 'fileWrite' (1) and Bad 'file' pointer @ 'fileClose' (1). Thanks

Link to comment

fileOpen returns a file userdata, which you must use for fileWrite and fileClose.

local playerName = getPlayerName( source  ) 
local levelAdmin = getElementData ( source, "Admin" ) 
local stringName = string.format ( "Users/%s.ini", playerName ) 
local stringAdmin = string.format ( "Admin: %i\n", levelAdmin ) 
local file = fileOpen ( stringName  ) 
if ( file ) then 
    fileWrite ( file, stringAdmin ) 
    fileClose ( file ) 
end 

Link to comment

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...