Reading and Writing with Files

Step 5. Make a temp folder, file and read a file

To work with text files, you'll probably want a folder or primary location where you are going to store files that you read and write. In this example we want to create a folder on the c:/ drive named "temp".

Let me show you why, if you Click Start on the "ReadFile" script (without the "c:/temp" folder and a text file to read, you will get an error message stating "File does not exist". User-inserted image

Lets look at the code of this script to see how our file is called up to read it. Click on the gear icon (settings) for the "ReadFile" script. User-inserted image

The first line in our script sets a variable named $filename equal to the path and file name of "c:\temp\myfile.txt" Then we see and "IF" clause that if the file and path can not be found, then print out on the screen "File does not exist", just as we saw when we ran the script a moment ago. The script is then halted.

This is a very good function to include when reading or writing files, because text files might get deleted or moved or just stuck depending on what you might be doing with files and how much you are using them. So making sure your script has an "out" method such as this to check the path and halt the program. It is a smart way to address any issues that might come up when working with text files.

Before going further, lets make sure you have created a temp folder on your c:\ drive. User-inserted image

Now create a text file in the folder, by right clicking in the folder and select Text Document. User-inserted image

Name the file "myfile". User-inserted image

Now enter some lines of text in the file and be sure to save it! User-inserted image

Now lets run the "ReadFile" script again. You should get the following successfully outcome from reading the file. Each line should be read and output until the end of the file is reached. User-inserted image


ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

#1  

can the read text be a script?

#2  

Josh, I'm not sure I understand your question.  You would want to read the text contained within an EZ-Script?

#3  

well I was thinking of a script in the notepad file , so for example if you had questions and answers worked out but you also wanted a movement to accompany a response. Like eye brows raise when answering.   Maybe im not explaining it clearly , but I was imagining using word files as large memory for responses instead of placed inline with all the other scripts and code so ARC doesnt have to pass through them every cycle making it slower the larger amount of scripting there.

#4   — Edited

I think I see where you are going.

Let me add this to the "reading" of the files and data, while I can have a txt file with data in and have an EZ-Script read it does not mean my robot has "understanding" of it.  To create the connections and understanding to understand that a word like "Justin" or "Josh" relates to a person and who that person is requires more scripting, which I think is what your point is.

Your idea is instead of adding that extra scripting in an EZ-Script is add it to your text file or note pad file.

That is a pretty cool idea and I would say you can do it, to a certain level of difficulty.  I don't think you would want to try to build out an advanced AI full of scripts in text files because I think that approach would become unmanageable.

But like you said, if you want certain actions or scripts to active when lines are read in a text a file, you could make a comma separated file and insert your scripted commands among text separated by commas, but be mindful of any commas in your command control or action script call names so you tell ReadFile to split the read back at the spots.

#5  

So I did a quick experiment and here are some issues, you can add scripted data in your text file or comma separated file for an EZ-Script to take action on, but as you read in the lines you will assign them out to variables - which you then need to translate to an action or ez-script.  I don't see a way for ARC to understand its own scripting language from a file or to directly re-translate it.

This is why in the past I have used my own short hand commands in text files for the robot to read such as:

Justin Ratliff,Smile Josh,Wave DJ,Faint

That data might be in text file for people my robot knows and my scripts then use IF-THEN logic to carry out other scripts and actions based on those indicators in the text file like "Smile, Wave, Faint, etc." as examples.

PRO
Synthiam
#6  

You can make an ARC skill plugin control that loads txt files and executes them. It'll be pretty easy to do - but i'm not sure why you'd want to do that yet. Can you give me a use-case? Is it to avoid having lots of script windows? Or to avoid having a script manager with lots of items in it?

#7  

yes basically not have a ton of script windows open

#8  

it seems like it could be cleaner if you could congregate them in a memo txt doc

PRO
Synthiam
#9  

What about the script manager? Wouldn't that be the same thing?