Jump to content

fileCreate don't work !


PaiN^

Recommended Posts

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 .

Link to comment

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

Link to comment

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 

Link to comment
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 ?

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