File I/O Tool
1 Attachment(s)
This is a neat file I/O tool I made for [URL="http://www.alice.org/community/member.php?u=18410"]TauTrumpsPi[/URL].
Import the object into the world you want to use it in. Don't rename it and don't delete any of its variables, methods or events. Set IOTool's variable named current_file to the file to be used. Change it when necessary. Use any of its methods wherever required. Some methods have basic help/info in comments inside them. Any method that returns a value (eg read_all or get_lines) will write its value to IOTool's variable named returnString (or returnNumber for get_lines). Update 1.1 - should work perfectly now. Update 1.2 - now it actually definitely works; trialled and tested. [B] New Version Available - [URL="http://alice.org/community/showthread.php?p=45897"]Save Tool[/URL] - for specifically saving and loading variables[/B] [B]Read below only if you require help:[/B] [SIZE=1][I][B]get_value[/B][/I] - returns to [U][I]returnString[/I][/U] - parameter [U][I]value[/I][/U] is the name of the value key - returns info about the file (eg size). [I][B]new_file[/B][/I] - returns [U]none[/U] - parameter [U][I]filename[/I][/U] is the complete folder, file,ext name (ie C:\Users\Me\Documents\blank.txt). [I][B]new_folder[/B][/I] - returns [U]none[/U] - parameter [U][I]dirname[/I][/U] is the complete pathname of the directory (ie C:\Users\Me\Documents\folder). [B]read_all[/B] - returns to [U][I]returnString[/I][/U] - [U]no[/U] parameters - reads the entire file. [B]read_line[/B] - returns to [U][I]returnString[/I][/U] -parameter line is the line to read - reads only a given line from the file. [B]get_lines[/B] - returns to [U][I]returnNumber[/I][/U] -[U]no[/U] parameters - returns the number of lines of text in the file. [B]write[/B] - returns [U]none[/U] - parameter [U][I]text[/I][/U] is the string to write with - writes over everything in the file. [B]write_line[/B] - returns [U]none[/U] - parameter [U][I]text[/I][/U] is the string to write with, [U][I]line[/I][/U] is the line to write over - writes over everything on only the specified line in the file. [B]write_append[/B] - returns [U]none[/U] - parameter [U][I]text[/I][/U] is the string to write with - writes onto the end of the file, retaining any text already in it. [B]delete_file[/B] - returns [U]none[/U] - [U]no[/U] parameters - completely removes the file from disc. [B]replace_file[/B] - returns [U]none[/U] - parameter [U][I]file_to_overwrite_with[/I][/U] is the complete filename of the file to write with - replaces the current file with the contents of another file, replaces in binary, so can replace with images etc. [B]rename_file[/B] - returns [U]none[/U] - parameter [U][I]name[/I][/U] is the new name to give the file, set [U][I]full_path[/I][/U] to true to change complete filename; or to false just to change name relative to the director[/SIZE]y it is in - renames the file. [SIZE=2][B]Support me by using [URL="http://adf.ly/8J02s"][B][SIZE=2]this DOWNLOAD link[/SIZE][/B][/URL][/B] (AdF.ly)[/SIZE] |
[QUOTE=arty-fishL;37453]This is a neat file I/O tool I made for [URL="http://www.alice.org/community/member.php?u=18410"]TauTrumpsPi[/URL].
Import the object into the world you want to use it in. Don't rename it and don't delete any of its variables, methods or events. Set IOTool's variable named current_file to the file to be used. Change it when necessary. Use any of its methods wherever required. Some methods have basic help/info in comments inside them. Any method that returns a value (eg read_all or get_lines) will write its value to IOTool's variable named returnString (or returnNumber for get_lines). [B]Read below only if you require help:[/B] [SIZE=1][I][B]get_value[/B][/I] - returns to [U][I]returnString[/I][/U] - parameter [U][I]value[/I][/U] is the name of the value key - returns info about the file (eg size). [I][B]new_file[/B][/I] - returns [U]none[/U] - parameter [U][I]filename[/I][/U] is the complete folder, file,ext name (ie C:\Users\Me\Documents\blank.txt). [I][B]new_folder[/B][/I] - returns [U]none[/U] - parameter [U][I]dirname[/I][/U] is the complete pathname of the directory (ie C:\Users\Me\Documents\folder). [B]read_all[/B] - returns to [U][I]returnString[/I][/U] - [U]no[/U] parameters - reads the entire file. [B]read_line[/B] - returns to [U][I]returnString[/I][/U] -parameter line is the line to read - reads only a given line from the file. [B]get_lines[/B] - returns to [U][I]returnNumber[/I][/U] -[U]no[/U] parameters - returns the number of lines of text in the file. [B]write[/B] - returns [U]none[/U] - parameter [U][I]text[/I][/U] is the string to write with - writes over everything in the file. [B]write_line[/B] - returns [U]none[/U] - parameter [U][I]text[/I][/U] is the string to write with, [U][I]line[/I][/U] is the line to write over - writes over everything on only the specified line in the file. [B]write_append[/B] - returns [U]none[/U] - parameter [U][I]text[/I][/U] is the string to write with - writes onto the end of the file, retaining any text already in it. [B]delete_file[/B] - returns [U]none[/U] - [U]no[/U] parameters - completely removes the file from disc. [B]replace_file[/B] - returns [U]none[/U] - parameter [U][I]file_to_overwrite_with[/I][/U] is the complete filename of the file to write with - replaces the current file with the contents of another file, replaces in binary, so can replace with images etc. [B]rename_file[/B] - returns [U]none[/U] - parameter [U][I]name[/I][/U] is the new name to give the file, set [U][I]full_path[/I][/U] to true to change complete filename; or to false just to change name relative to the director[/SIZE]y it is in - renames the file.[/QUOTE] Cool! It looks interesting! |
I can't get it to work... It seems like you're missing an integer variable of some sort
Here's the error [code] Error during simulation. Alice version: 2.2 02/10/2011 Throwable that caused the error: Traceback (innermost last): File "edu.cmu.cs.stage3.alice.core.property.ScriptProperty[name=script,owner=edu.cmu.cs.stage3.alice.core.response.ScriptResponse[world.iOTool.read_all.__Unnamed0__]]", line 1, in ? NameError: fileinfo [/code] |
My head is spinning, partly because Arty just made a new manly batch of awesome, but also partly because I don't know what to do with it.
Can you write new .txt files with it? |
[QUOTE=TauTrumpsPi;37467]I can't get it to work... It seems like you're missing an integer variable of some sort
Here's the error [/QUOTE]Give it a second to start before you use it, don't use it on world start. If that doesn't work, do you have an [I]"on world start" [/I]event under the IOTool heading? If you don't then there should be one. [QUOTE=DensetsuNoKaboom;37494]Can you write new .txt files with it?[/QUOTE]Yes, and read them. (they don't have to end in .txt, but they should be plain text files ie. not images etc.) |
I got it! Thank you!
|
Thanks! This will be very useful!
|
[quote=arty-fishl;37504]
yes, and read them. (they don't have to end in .txt, but they should be plain text files ie. Not images etc.)[/quote] Hmmm... ... ... ... ... ... ... ... ... ... :D:D:D:D:D EDIT: It's not working. It creates new files all right but when I try to make it write a string variable to line 1 of the created file, it gives me an error. [quote]Error during simulation. Alice version: 2.2 02/10/2011 Throwable that caused the error: Traceback (innermost last): File "edu.cmu.cs.stage3.alice.core.property.ScriptProperty[name=script,owner=edu.cmu.cs.stage3.alice.core.response.ScriptResponse[world.iOTool.write_line.__Unnamed0__]]", line 1, in ? File "<string>", line 7, in __init__ AttributeError: class 'org.python.modules.os' has no attribute 'path' [/quote] |
Mr. Kidnapper does not understand the uses of this. Is it supposed to assist in creating save/load states?
|
That is the reason I originally asked for it, yes.
|
Having the same error as densestu.:(
btw, you should add a method that converts strings into numbers:) |
[QUOTE=room14;37562]Having the same error as densestu.:(
btw, you should add a method that converts strings into numbers:)[/QUOTE] Yeah, so you can make it read a "number" that is in the file and change it to a number and set a variable to that number, so it wouldn't be just strings you can save! |
I haven't come up with anything to use it for yet, but it is sounds very cool!
|
I updated it to a working version.
I'm considering the other suggested features. |
[QUOTE=arty-fishL;37593]I updated it to a working version.
I'm considering the other suggested features.[/QUOTE] Really now? [quote]Error during simulation. Alice version: 2.2 02/10/2011 Throwable that caused the error: Traceback (innermost last): File "edu.cmu.cs.stage3.alice.core.property.ScriptProperty[name=script,owner=edu.cmu.cs.stage3.alice.core.response.ScriptResponse[world.iOTool.event.__Unnamed0__]]", line 1, in ? File "<string>", line 1, in ? SyntaxError: ('future feature division is not defined', ('C:\\Documents and Settings\\*\\My Documents\\Alice22\\Required\\jython-2.1\\Lib\\javaos.py', 23, 6, '')) [/quote] Future feature division? EDIT: I think you should also know that this error occurs when I start playing a world with the object in it. |
If you want uses, then you could use it to save PoV locations, booleans, and other number variables constantly every second to, for example, make a game a bit like Harvest Moon or other example sim game. In fact, I would applaud you for making a persistent world sim game. Persistent World could be achieved by making the world relative to computer date time, if you didn't know how.
|
You know, I find it funny that I ask you to do this and then a week later I learn how to do it in C++. Odd coincedence.
|
I worked out what was wrong, its fixed.
Its updated and definitely works now, I tested it on a non-modified Alice. |
[QUOTE=arty-fishL;37628]I worked out what was wrong, its fixed.
Its updated and definitely works now, I tested it on a non-modified Alice.[/QUOTE] [quote]Error during simulation. Alice version: 2.2 02/10/2011 Throwable that caused the error: Traceback (innermost last): File "edu.cmu.cs.stage3.alice.core.property.ScriptProperty[name=script,owner=edu.cmu.cs.stage3.alice.core.response.ScriptResponse[world.iOTool.write_line.__Unnamed0__]]", line 1, in ? File "<string>", line 153, in writeline IndexError: index out of range: -1 [/quote] Bbbbububbuubuubbubut... At least this time, it didn't happen until I tried to write a variable to line 1. EDIT: And hey, it works when I overwrite the entire file with text rather than one line! And it works when I load that file! EDIT2: And this is my 600th post! |
No, that's just you using it wrong.
You cant write to line 1, because line 1 doesn't exist. It is like a list, it starts at line 0. If you want a new line at any time just add in [I]\n[/I] . Once the line exists you can write to it. |
[QUOTE=arty-fishL;37631]
If you want a new line at any time just add in [I]\n[/I] . [/QUOTE] Add it in where? |
Wherever you're writing just add [I]\n[/I] into the string for a new line. For example:
"hi there \n my name is Bob\nGreat!" would produce [CODE]hi there my name is Bob Great![/CODE] Anyway, what you were looking for was writing to line 0, not line 1. I could maybe update it to change writing line 0 to line 1 instead (so the numbers are shifted down one) and so on. I could also add a function to create a new line or set of lines; one for changing a string to a number; maybe even also a variable saving function. |
It failed as well when I tried writing to line 0.
|
[QUOTE=DensetsuNoKaboom;37684]It failed as well when I tried writing to line 0.[/QUOTE]Ensure the file exists first - use new_file with overwrite set to false. If writing to line 0 doesn't work then try using write. It should work, I've tested it lots.
|
Is this compatible with Mac OS X? I recognized it started with C:// so I changed it to the Mac filepath and when I ran the world it threw an error:
Error during simulation. Alice version: 2.2 09/10/2010 Throwable that caused the error: Traceback (innermost last): File "edu.cmu.cs.stage3.alice.core.property.ScriptProperty[name=script,owner=edu.cmu.cs.stage3.alice.core.response.ScriptResponse[world.iOTool.event.__Unnamed0__]]", line 1, in ? File "<string>", line 26, in ? File "<string>", line 12, in patchOS IOError: File not found - jython-2.1\Lib\javaos.py (No such file or directory) |
[QUOTE=Dj Tech42;38233]Is this compatible with Mac OS X? I recognized it started with C:// so I changed it to the Mac filepath and when I ran the world it threw an error:
Error during simulation. Alice version: 2.2 09/10/2010 Throwable that caused the error: Traceback (innermost last): File "edu.cmu.cs.stage3.alice.core.property.ScriptProperty[name=script,owner=edu.cmu.cs.stage3.alice.core.response.ScriptResponse[world.iOTool.event.__Unnamed0__]]", line 1, in ? File "<string>", line 26, in ? File "<string>", line 12, in patchOS IOError: File not found - jython-2.1\Lib\javaos.py (No such file or directory)[/QUOTE]Ehh, sorry, it seems your version (either your version is broken or Mac version is broken) of Alice has its file directory incorrectly referenced. You could try updating Alice, there's a newer version of 2.2 available, but I'm not sure that will help. |
I already have the latest version. I think it has something to do with the file system being different on Mac OS X. I think this is a very important feature that needs to be implemented into Alice and I am sad that it isn't working :(
|
Is there a way I can change how Alice accesses the internal files? It can't find one of its own files, which is really annoying
|
[QUOTE=Dj Tech42;38237]I already have the latest version. I think it has something to do with the file system being different on Mac OS X. I think this is a very important feature that needs to be implemented into Alice and I am sad that it isn't working :([/QUOTE]Oh, the latest Windows version is a 2011 version, youve got a 2010 (maybe Mac isn't as updated yet).
[QUOTE=Dj Tech42;38238]Is there a way I can change how Alice accesses the internal files? It can't find one of its own files, which is really annoying[/QUOTE]Elaborate on this error, I may be able to help. What file cant it find? |
/Applications/Alice 2.2.app/Contents/Required/jython-2.1/Lib/javaos.py
javaos.py is the file it is looking for, and I know where it is ^. Is there some way I can show Alice where to look for the file? And the Mac version was released September 2010. |
It's still coming up with the error no matter what I do
|
1 Attachment(s)
[QUOTE=Dj Tech42;38552]It's still coming up with the error no matter what I do[/QUOTE]Sorry about taking ages to respond. Try this world. Play it in Alice, wait for it to finish, then try restarting Alice.
|
It says patch failed :(
|
1 Attachment(s)
[QUOTE=Dj Tech42;38746]It says patch failed :([/QUOTE]
OK, try the new one, even if it doesn't work, it will print out debug info so I can see what is wrong |
Ok here's what it said:
START PATCH Resource Transfer patch failed Debug: File not found - resources\common\ResourceTransfer.py (No such file or directory) Patch failed END PATCH |
The said file does exist, but it is under required/resources/common/
|
[QUOTE=Dj Tech42;38857]The said file does exist, but it is under required/resources/common/[/QUOTE]Sorry I am late again, I've been busy elsewhere - and in thinking about this. I'm at a loss, if it can't even be patched then I don't know what to do.
You haven't by chance stuck Alice in the system programs directory instead of your local home directory have you? Because if you have, then I would try moving it to a folder on your local home directory instead, the error may lay with permissions or similar. |
It's ok, you don't need to worry about it anymore. I can't even run Alice 2.2 on my computer now due to the code in Alice being too old.
|
Well, Alice 2.2 is running on my computer again, but still no luck with the plugin. :( I will probably have to try it on a different computer.
|
I think I might have fixed it! I enabled scripting on Alice and fixed the javaos.py path reference! I just need to try the actual methods now.
It worked! Thanks so much arty for creating such an awesome tool! |
All times are GMT -5. The time now is 11:46 PM. |
Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.