| Blockland Forums > Modification Help |
| How do I add an item, delete an item, and get an item from a text file? |
| << < (2/3) > >> |
| Axolotl:
--- Quote from: cheese6 on December 19, 2011, 06:43:17 PM ---When using the FileObject functions, the openForWrite will create the file, so will the openToAppend (I think). To check if there is a file, do if(isFile(%path)) { //yes } else { //no } Enjoi. --- End quote --- Thanks |
| Axolotl:
--- Quote from: Ipquarx on December 19, 2011, 06:33:17 PM ---To read, its the same thing, just change a couple things: --- Code: ---%blah = new FileObject(); %blah.openForRead("filepath"); %blah.readLine(); %blah.close(); %blah.delete(); --- End code --- --- End quote --- Oops, I meant to read a specific item. What I am saying is to see if a certain item is in the text file. |
| jes00:
--- Quote from: Axolotl on December 19, 2011, 07:38:45 PM ---Oops, I meant to read a specific item. What I am saying is to see if a certain item is in the text file. --- End quote --- --- Code: ---function FUNCTION_NAME(%string) { %file = new FileObject(); %file.openForRead("File/path/here"); while(!%file.isEOF()) { %line = %file.readLine(); if(%line $= %string) { %file.close(); %file.delete(); return 1; } } %file.close(); %file.delete(); return 0; } --- End code --- Now you can just call FUNCTION_NAME(%item); |
| Axolotl:
--- Quote from: jes00 on December 19, 2011, 07:44:27 PM --- --- Code: ---function FUNCTION_NAME(%string) { %file = new FileObject(); %file.openForRead("File/path/here"); while(!%file.isEOF()) { %line = %file.readLine(); if(%line $= %string) { %file.close(); %file.delete(); return 1; } } %file.close(); %file.delete(); return 0; } --- End code --- Now you can just call FUNCTION_NAME(%item); --- End quote --- thanks jes |
| Axolotl:
--- Quote from: jes00 on December 19, 2011, 07:44:27 PM --- --- Code: ---function FUNCTION_NAME(%string) { %file = new FileObject(); %file.openForRead("File/path/here"); while(!%file.isEOF()) { %line = %file.readLine(); if(%line $= %string) { %file.close(); %file.delete(); return 1; } } %file.close(); %file.delete(); return 0; } --- End code --- --- End quote --- wait, to look specifically in a line for that item (example: I am searching for 1 but I don't want 12, I specifically want 1) do I just replace if(%line $= %string) with if(%line == %string)? EDIT: nvm |
| Navigation |
| Message Index |
| Next page |
| Previous page |