Jump to content

fileCreate don't work !


PaiN^

Recommended Posts

Posted

Hi,

I have this code : [client]

addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if source == GUIEditor.button[1] then 
            local fileName = guiGetText ( GUIEditor.edit[1] ) 
            if string.len(fileName) > 1 then 
                if fileExists ( fileName..'.lua' ) then 
                    outputChatBox ( '*Error : A file with that name allready exists !', 255, 0, 0 ) 
                    guiSetText ( GUIEditor.edit[1], '' ) 
                else 
                    the_file = fileCreate ( fileName..'.lua' ) 
                    if ( the_file ) then 
                        outputChatBox ( 'file '..fileName..' was created !' ) 
                        guiSetText ( GUIEditor.edit[1], '' ) 
                        guiSetVisible ( GUIEditor.window[1], false ) 
                    end 
                end 
            end  
        end 
    end 
) 

And i have the resource as a folder not .zip, When i press the button it says that the file was created, When i try to make another file with the same name it says that it exists .

But when i go to the resource folder i find nothing there, Can any one tell me why .?

Thank you in advanced .

Posted

You have to flush/close the file. When you fileCreate a file it is stored in memory, once you fileClose it will appear in the folder. Always CLOSE opened files!

Posted

I tried this :

addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if source == GUIEditor.button[1] then 
            fileName = guiGetText ( GUIEditor.edit[1] ) 
            if string.len(fileName) > 1 then 
                if fileExists ( fileName..'.lua' ) then 
                    outputChatBox ( '*Error : A file with that name allready exists !', 255, 0, 0 ) 
                    guiSetText ( GUIEditor.edit[1], '' ) 
                else 
                    the_file = fileCreate ( fileName..'.lua' ) 
                    if ( the_file ) then 
                        guiSetText ( GUIEditor.edit[1], '' ) 
                        guiSetVisible ( GUIEditor.window[1], false ) 
                        guiSetVisible ( GUIEditor.window[2], true ) 
                    end 
                    fileClose ( the_file ) 
                end 
            end  
        end 
    end 
) 

And this :

addEventHandler ( 'onClientGUIClick', root, 
    function ( ) 
        if source == GUIEditor.button[1] then 
            fileName = guiGetText ( GUIEditor.edit[1] ) 
            if string.len(fileName) > 1 then 
                if fileExists ( fileName..'.lua' ) then 
                    outputChatBox ( '*Error : A file with that name allready exists !', 255, 0, 0 ) 
                    guiSetText ( GUIEditor.edit[1], '' ) 
                else 
                    the_file = fileCreate ( fileName..'.lua' ) 
                    if ( the_file ) then 
                        guiSetText ( GUIEditor.edit[1], '' ) 
                        guiSetVisible ( GUIEditor.window[1], false ) 
                        guiSetVisible ( GUIEditor.window[2], true ) 
                        fileClose ( the_file ) 
                    end 
                end 
            end  
        end 
    end 
) 

Bad 'file' pointer @ fileClose (1)

And i tried it with fileFlush, Same error ..

Posted

As previously announced 50p you should make the little bit different.

-- this is only a test and untested!! 
function writeFile() 
    local file -- only a declaration 
    if fileExists("_your_lua_file.lua") then 
        file = fileOpen("_your_lua_file.lua") 
    else 
        file = fileCreate("_your_lua_file.lua") 
    end 
     
    if file then 
        fileWrite(file, "your_text", ...) -- writing 
        fileClose(file) 
    else 
        outputDebugString("An error has occurred!") 
    end 
end 

And the simplified form:

-- this is only a test and untested!! 
function writeFile() 
    local file = fileExists("_your_lua_file.lua") and fileOpen("_your_lua_file.lua") or fileCreate("_your_lua_file.lua") 
     
    if file then 
        fileWrite(file, "your_text", ...) -- writing 
        fileClose(file) 
    else 
        outputDebugString("An error has occurred!") 
    end 
end 

Posted

Just make sure where ever you open, you close. You would be surprised the destructive power it has when you open when there is one already opened or vice versa.

Posted
Your,Script right and there is no errors, but the file is created in the resources folder and i try it now and it works well!

I know where it should be created, but it isn't creating it DX

Can i send you full code on PM ?

Posted
Hmmm... i just test it and work's :? i got the files's in this file :

C:\Program Files (x86)\MTA San Andreas 1.3\mods\deathmatch\resources\xCreateFileResource 

I have sent you the code, Check your PMs ..

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