Need some help with the file reader

Post here if you need help using Actiona
Post Reply
fransg
Posts: 5
Joined: 23 Apr 2012, 20:10

Need some help with the file reader

Post by fransg »

Hi! I'm working on a bot for a game , and I need that bot to open a .txt file with some accounts , ex :
Account1
Account2
Account3
...
And then use the first account to log in the game , and when the first ends use the second one , untill the list end.
How can i make this happen? i mean , i think i need to put my .txt into a string variable .
Then somehow find the number of accounts that .txt file have , and then substract one by one.
But dont know how to make it works.

Another question i got is that my .txt is on "C://Documents...." . But i want it to be a relative link becouse i want to share it with some friends .
Thanks and i hope it's all clear and understandable.
User avatar
Jmgr
Admin
Posts: 1649
Joined: 07 Dec 2005, 15:45
Contact:

Re: Need some help with the file reader

Post by Jmgr »

This should get you started: (Go to file->Import->Script content to import it)

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<scriptfile>
    <settings program="actionaz" version="3.4.1" scriptVersion="1.0.0" os="Windows"/>
    <actions>
        <action name="ActionGoto" version="1.0.0"/>
        <action name="ActionMessageBox" version="1.0.0"/>
        <action name="ActionVariable" version="1.0.0"/>
        <action name="ActionReadTextFile" version="1.0.0"/>
        <action name="ActionVariableCondition" version="1.0.0"/>
        <action name="ActionStop" version="1.0.0"/>
    </actions>
    <parameters/>
    <script pauseBefore="0" pauseAfter="0">
        <action name="ActionVariable" comment="Line = 1">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <exception id="32" action="0" line=""/>
            <parameter name="colorValue">
                <subParameter name="value" code="0">::</subParameter>
            </parameter>
            <parameter name="variable">
                <subParameter name="value" code="0">line</subParameter>
            </parameter>
            <parameter name="type">
                <subParameter name="value" code="0">integer</subParameter>
            </parameter>
            <parameter name="value">
                <subParameter name="value" code="0">1</subParameter>
            </parameter>
            <parameter name="positionValue">
                <subParameter name="value" code="0">:</subParameter>
            </parameter>
        </action>
        <action name="ActionReadTextFile" label="read" comment="Read one line">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <exception id="32" action="0" line=""/>
            <parameter name="firstline">
                <subParameter name="value" code="1">line</subParameter>
            </parameter>
            <parameter name="mode">
                <subParameter name="value" code="0">selection</subParameter>
            </parameter>
            <parameter name="variable">
                <subParameter name="value" code="0">out</subParameter>
            </parameter>
            <parameter name="file">
                <subParameter name="value" code="0">test.txt</subParameter>
            </parameter>
            <parameter name="lastline">
                <subParameter name="value" code="1">line</subParameter>
            </parameter>
        </action>
        <action name="ActionVariableCondition" comment="If we read nothing, then we are done">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <parameter name="ifEqual">
                <subParameter name="line" code="0">stop</subParameter>
                <subParameter name="action" code="0">goto</subParameter>
            </parameter>
            <parameter name="comparison">
                <subParameter name="value" code="0">equal</subParameter>
            </parameter>
            <parameter name="variable">
                <subParameter name="value" code="0">out</subParameter>
            </parameter>
            <parameter name="value">
                <subParameter name="value" code="0"></subParameter>
            </parameter>
            <parameter name="ifDifferent">
                <subParameter name="line" code="0"></subParameter>
                <subParameter name="action" code="0">do_nothing</subParameter>
            </parameter>
        </action>
        <action name="ActionMessageBox">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <parameter name="windowIcon">
                <subParameter name="value" code="0"></subParameter>
            </parameter>
            <parameter name="message">
                <subParameter name="value" code="0">Read: $out</subParameter>
            </parameter>
            <parameter name="title">
                <subParameter name="value" code="0"></subParameter>
            </parameter>
            <parameter name="textMode">
                <subParameter name="value" code="0">automatic</subParameter>
            </parameter>
            <parameter name="ifYes">
                <subParameter name="line" code="0"></subParameter>
                <subParameter name="action" code="0">do_nothing</subParameter>
            </parameter>
            <parameter name="customIcon">
                <subParameter name="value" code="0"></subParameter>
            </parameter>
            <parameter name="icon">
                <subParameter name="value" code="0">none</subParameter>
            </parameter>
            <parameter name="type">
                <subParameter name="value" code="0">ok</subParameter>
            </parameter>
            <parameter name="ifNo">
                <subParameter name="line" code="0"></subParameter>
                <subParameter name="action" code="0">do_nothing</subParameter>
            </parameter>
        </action>
        <action name="ActionVariable" comment="Line = Line + 1">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <exception id="32" action="0" line=""/>
            <parameter name="colorValue">
                <subParameter name="value" code="0">::</subParameter>
            </parameter>
            <parameter name="variable">
                <subParameter name="value" code="0">line</subParameter>
            </parameter>
            <parameter name="type">
                <subParameter name="value" code="0">integer</subParameter>
            </parameter>
            <parameter name="value">
                <subParameter name="value" code="1">line + 1</subParameter>
            </parameter>
            <parameter name="positionValue">
                <subParameter name="value" code="0">:</subParameter>
            </parameter>
        </action>
        <action name="ActionGoto" comment="Go to line "read"">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <parameter name="line">
                <subParameter name="value" code="0">read</subParameter>
            </parameter>
        </action>
        <action name="ActionStop" label="stop">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
        </action>
    </script>
</scriptfile>
Another question i got is that my .txt is on "C://Documents...." . But i want it to be a relative link becouse i want to share it with some friends .
You can enter a path relative to the directory where Actionaz is installed. If the file is in the same directory as the Actionaz executable then you can simply enter the name of the file.
"My software never has bugs. It just develops random features."
fransg
Posts: 5
Joined: 23 Apr 2012, 20:10

Re: Need some help with the file reader

Post by fransg »

Wow , thanks!
I just had to play a bit with your script to get how it works . Then I changed some things to fit on my script, like comparing the first line of accounts.txt to the accountsfinishd.txt , so it works all time with the one is not completed.
You have been very helpful ! Thanks!!!
fransg
Posts: 5
Joined: 23 Apr 2012, 20:10

Re: Need some help with the file reader

Post by fransg »

Hi , You solved my first question .
But now, one month later I have another one and I hope you can help me to solve it.
I developed my own bot and it works perfectly but right now is working with an account.txt, accountfinished.txt and password.txt.
It checks the accounts one per one with the accountfinished.txt. If the account isn't in accountfinished.txt it plays with that account. But the problem here is my password.txt just contains a password that all account have to share for work and I want to have all my accounts with an unique password .So my account.txt have to be like :
Account1:Password1
Account2:Password2
etc..
How should I separate them in diferents variables ?
Thanks for all!
User avatar
Jmgr
Admin
Posts: 1649
Joined: 07 Dec 2005, 15:45
Contact:

Re: Need some help with the file reader

Post by Jmgr »

You could use some Javascript to do that. See the split function : http://www.w3schools.com/jsref/jsref_split.asp.
To enable Javascript in a field, click on the red triangle on the right.
"My software never has bugs. It just develops random features."
fransg
Posts: 5
Joined: 23 Apr 2012, 20:10

Re: Need some help with the file reader

Post by fransg »

Thanks!!
Now I can randomize all :p
I knew about the split function and I tried it before that post , but i've never write in javascript and I tried writing it like :
(accounts contains one of the lines of the accounts.txt)
var accs = accounts;
var n=accs.split(":");
and it didn't work.The reason was I had to wrote like this :
var accs = accounts+"";
Don't know why. Maybe without the +"" it didn't detect it as a String?
Well whatever it worked ! Thanks again:P!
User avatar
Jmgr
Admin
Posts: 1649
Joined: 07 Dec 2005, 15:45
Contact:

Re: Need some help with the file reader

Post by Jmgr »

Strange, what was the error that you were getting ?
"My software never has bugs. It just develops random features."
fransg
Posts: 5
Joined: 23 Apr 2012, 20:10

Re: Need some help with the file reader

Post by fransg »

It showed that error :
Uncaught exception at <anonymous script, id=101071520>:2: TypeError: Result of expression 'accs.split' [undefined] is not a function.
2 var n=accs.split(":");
Then I added +"" when I declared the "accs" variable and it worked correctly.
Wh4xer
Posts: 9
Joined: 04 Jul 2012, 16:38

Re: Need some help with the file reader

Post by Wh4xer »

Hey, i also need a text file with accounts like that, but i dont get a shit of:

var accs = accounts;
var n=accs.split(":");
and it didn't work.The reason was I had to wrote like this :
var accs = accounts+"";


what is this and how do i make it split so i can have 1 variable where it takes the username and another one where it takes the password? plz, help me :D
User avatar
Jmgr
Admin
Posts: 1649
Joined: 07 Dec 2005, 15:45
Contact:

Re: Need some help with the file reader

Post by Jmgr »

(sorry for the late answer, I was on vacation)

Well, split returns an array. This means that you can get the number of elements it contains by using n.length, and access each element using [] such as n[1] to get the second element. (it starts at 0)
See any Javascript tutorial for more info.

In your case this yould mean that the username is at the first position and the password at the second position.
"My software never has bugs. It just develops random features."
srex
Posts: 2
Joined: 26 Nov 2013, 03:03

Re: Need some help with the file reader

Post by srex »

I'm trying to do the same here i want the bot to read a .txt file in following format:
username:password
and the type it on two lines in the game League of Legends.
Their game currently has following format on login screen:
Username
Password

I (think) I understand the Javascript needed for this task

Code: Select all

var str = "username:password";
var res = str.split(":",2");
however im a little confused on where to type this code, and how to get it to work.
So it splits the 2 informations (a username and a password) into two varibles, and then the "write text"
takes one of the informations and place it on their correct spot
User avatar
Jmgr
Admin
Posts: 1649
Joined: 07 Dec 2005, 15:45
Contact:

Re: Need some help with the file reader

Post by Jmgr »

You could type it in a Code action, and then use $res[0] and $res[1] in a Write Text action to write the username and the password.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<scriptfile>
    <settings program="actionaz" version="3.6.1" scriptVersion="1.0.0" os="GNU/Linux"/>
    <actions>
        <action name="ActionCode" version="1.0.0"/>
        <action name="ActionWriteText" version="1.0.0"/>
    </actions>
    <parameters/>
    <script pauseBefore="0" pauseAfter="0">
        <action name="ActionCode">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <parameter name="code">
                <subParameter name="value" code="1">var str = "username:password";
var res = str.split(":");</subParameter>
            </parameter>
        </action>
        <action name="ActionWriteText">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <exception id="32" action="0" line=""/>
            <parameter name="text">
                <subParameter name="value" code="0">$res[0]</subParameter>
            </parameter>
            <parameter name="pause">
                <subParameter name="value" code="0">0</subParameter>
            </parameter>
        </action>
        <action name="ActionWriteText">
            <exception id="0" action="0" line=""/>
            <exception id="1" action="0" line=""/>
            <exception id="2" action="1" line=""/>
            <exception id="32" action="0" line=""/>
            <parameter name="text">
                <subParameter name="value" code="0">$res[1]</subParameter>
            </parameter>
            <parameter name="pause">
                <subParameter name="value" code="0">0</subParameter>
            </parameter>
        </action>
    </script>
</scriptfile>
"My software never has bugs. It just develops random features."
Post Reply