Alice Community  

Go Back   Alice Community > Alice 2 > Share Objects

Reply
 
Thread Tools Display Modes
File I/O Tool
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Lightbulb File I/O Tool - 06-14-2011, 05:15 PM

This is a neat file I/O tool I made for TauTrumpsPi.
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.

New Version Available - Save Tool - for specifically saving and loading variables




Read below only if you require help:

get_value - returns to returnString - parameter value is the name of the value key - returns info about the file (eg size).
new_file - returns none - parameter filename is the complete folder, file,ext name (ie C:\Users\Me\Documents\blank.txt).
new_folder - returns none - parameter dirname is the complete pathname of the directory (ie C:\Users\Me\Documents\folder).
read_all - returns to returnString - no parameters - reads the entire file.
read_line - returns to returnString -parameter line is the line to read - reads only a given line from the file.
get_lines - returns to returnNumber -no parameters - returns the number of lines of text in the file.
write - returns none - parameter text is the string to write with - writes over everything in the file.
write_line - returns none - parameter text is the string to write with, line is the line to write over - writes over everything on only the specified line in the file.
write_append - returns none - parameter text is the string to write with - writes onto the end of the file, retaining any text already in it.
delete_file - returns none - no parameters - completely removes the file from disc.
replace_file - returns none - parameter file_to_overwrite_with 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.
rename_file - returns none - parameter name is the new name to give the file, set full_path to true to change complete filename; or to false just to change name relative to the director
y it is in - renames the file.

Support me by using this DOWNLOAD link (AdF.ly)
Attached Files
File Type: a2c IOTool.a2c (37.4 KB, 86 views)

Last edited by arty-fishL; 05-08-2012 at 05:24 PM. Reason: updated - 1.2
   
Reply With Quote
Old
David B
Senior Member
 
David B's Avatar
 
Status: Offline
Posts: 1,145
Join Date: Dec 2010
Location: N/A
Default 06-14-2011, 05:44 PM

Quote:
Originally Posted by arty-fishL View Post
This is a neat file I/O tool I made for TauTrumpsPi.
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).





Read below only if you require help:

get_value - returns to returnString - parameter value is the name of the value key - returns info about the file (eg size).
new_file - returns none - parameter filename is the complete folder, file,ext name (ie C:\Users\Me\Documents\blank.txt).
new_folder - returns none - parameter dirname is the complete pathname of the directory (ie C:\Users\Me\Documents\folder).
read_all - returns to returnString - no parameters - reads the entire file.
read_line - returns to returnString -parameter line is the line to read - reads only a given line from the file.
get_lines - returns to returnNumber -no parameters - returns the number of lines of text in the file.
write - returns none - parameter text is the string to write with - writes over everything in the file.
write_line - returns none - parameter text is the string to write with, line is the line to write over - writes over everything on only the specified line in the file.
write_append - returns none - parameter text is the string to write with - writes onto the end of the file, retaining any text already in it.
delete_file - returns none - no parameters - completely removes the file from disc.
replace_file - returns none - parameter file_to_overwrite_with 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.
rename_file - returns none - parameter name is the new name to give the file, set full_path to true to change complete filename; or to false just to change name relative to the director
y it is in - renames the file.
Cool! It looks interesting!
   
Reply With Quote
Old
TauTrumpsPi
Senior Member
 
TauTrumpsPi's Avatar
 
Status: Offline
Posts: 399
Join Date: Mar 2011
Location: The diamond layer
Default 06-14-2011, 06:46 PM

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


--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes

Wondering about my Avatar?
http://en.wikipedia.org/wiki/Tardigrade

Wondering about my username?
http://www.youtube.com/watch?v=jG7vhMMXagQ
   
Reply With Quote
Old
DensetsuNoKaboom
Senior Member
 
DensetsuNoKaboom's Avatar
 
Status: Offline
Posts: 1,188
Join Date: May 2010
Location: e4eaf2
Default 06-15-2011, 06:29 AM

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?


Thank you for taking the time to read this signature. This signature loves you.
   
Reply With Quote
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Default 06-15-2011, 11:09 AM

Quote:
Originally Posted by TauTrumpsPi View Post
I can't get it to work... It seems like you're missing an integer variable of some sort

Here's the error
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 "on world start" event under the IOTool heading? If you don't then there should be one.

Quote:
Originally Posted by DensetsuNoKaboom View Post
Can you write new .txt files with it?
Yes, and read them. (they don't have to end in .txt, but they should be plain text files ie. not images etc.)


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [¬º-°]¬
   
Reply With Quote
Old
TauTrumpsPi
Senior Member
 
TauTrumpsPi's Avatar
 
Status: Offline
Posts: 399
Join Date: Mar 2011
Location: The diamond layer
Default 06-15-2011, 12:10 PM

I got it! Thank you!


--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes

Wondering about my Avatar?
http://en.wikipedia.org/wiki/Tardigrade

Wondering about my username?
http://www.youtube.com/watch?v=jG7vhMMXagQ
   
Reply With Quote
Old
Chao
Junior Member
 
Chao's Avatar
 
Status: Offline
Posts: 3
Join Date: May 2011
Location: United States, NY
Default 06-15-2011, 12:12 PM

Thanks! This will be very useful!
   
Reply With Quote
Old
DensetsuNoKaboom
Senior Member
 
DensetsuNoKaboom's Avatar
 
Status: Offline
Posts: 1,188
Join Date: May 2010
Location: e4eaf2
Default 06-15-2011, 05:03 PM

Quote:
Originally Posted by arty-fishl View Post
yes, and read them. (they don't have to end in .txt, but they should be plain text files ie. Not images etc.)
Hmmm...
...
...
...
...
...
...
...
...
...

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.ScriptPrope rty[name=script,owner=edu.cmu.cs.stage3.alice.core.res ponse.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'



Thank you for taking the time to read this signature. This signature loves you.

Last edited by DensetsuNoKaboom; 06-15-2011 at 05:16 PM.
   
Reply With Quote
Old
Mr Kidnapper
Senior Member
 
Status: Offline
Posts: 442
Join Date: Feb 2011
Default 06-15-2011, 05:33 PM

Mr. Kidnapper does not understand the uses of this. Is it supposed to assist in creating save/load states?
   
Reply With Quote
Old
TauTrumpsPi
Senior Member
 
TauTrumpsPi's Avatar
 
Status: Offline
Posts: 399
Join Date: Mar 2011
Location: The diamond layer
Default 06-15-2011, 06:06 PM

That is the reason I originally asked for it, yes.


--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes

Wondering about my Avatar?
http://en.wikipedia.org/wiki/Tardigrade

Wondering about my username?
http://www.youtube.com/watch?v=jG7vhMMXagQ
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.