PaiN^ Posted April 4, 2013 Share Posted April 4, 2013 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
50p Posted April 4, 2013 Share Posted April 4, 2013 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! Link to comment
PaiN^ Posted April 4, 2013 Author Share Posted April 4, 2013 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
krischkros Posted April 4, 2013 Share Posted April 4, 2013 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
OGF Posted April 4, 2013 Share Posted April 4, 2013 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. Link to comment
iPrestege Posted April 4, 2013 Share Posted April 4, 2013 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! Link to comment
PaiN^ Posted April 4, 2013 Author Share Posted April 4, 2013 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
iPrestege Posted April 4, 2013 Share Posted April 4, 2013 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 Link to comment
krischkros Posted April 4, 2013 Share Posted April 4, 2013 Please read carefully: https://wiki.multitheftauto.com/wiki/FileCreate @#Pai_[N] Link to comment
PaiN^ Posted April 4, 2013 Author Share Posted April 4, 2013 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 .. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now