Jump to content

reading a text file letter by letter then making IFTT statements


Recommended Posts

So I have tried a few different codes that ive found online in my searching and I dont know why its only ever position 0 or 31 no matter what im looking for in a line. I have a txt file that I have it pull and then I am trying to have it read the line and then id like it to search for the Second letter and tell me what that letter is and then the 3rd and 4th and so on so that I can then input if then statements depending on what comes next. if it would be easier or better to remove all the ", " then I could do that too. if it being something like 5LLRRLRLRRLRRLLLR is better than it currently is.

Example Lines from txt file:

1, L, R, L, R, R, L, R, L, R , L, L.... 

2, R, R, R, R, L, L, R, R, R, L, L....

what I would like to get i believe is an array of each line and then something like msgbox ("First Door is the " & $i & " Door") and then have certain actions happen based on if the same door L being Left or R being Right was opened and be able to continue it until the end of the line and then do some sort of msgbox like "Congrats you made it to the end adventurer!" or ill have it end the line and go to the next one if there ends up being a monster in the room that kills the player msgbox ("wamp wamp"). I Also plan on giving the player an option to exit the dungeon at some point so ill have to put pauses in at some point or ill prolly just code an exit and save last dungeon attempted counter or something but that's down the road.  Right now I'm just trying to understand how to get it to read the file and then let me put stuff between each letter read as if then statements and make the title the number at the beginning of each line. Please and thank you for your help I super appreciate it and I promise to upload my little dungeon crawler scenarios once i get it finished incase anyone is into stuff like that. 

Link to post
Share on other sites

i didnt realise we werent allowed to make games or scenarios i mean ive seen lots of posts about decks of cards and games and stuff, lol, thats where i found some of the most useful information here because people were doing fun silly things so i figured it was ok but i guess those posts just havent been shut down yet. even if its not for this specifically i still cannot for the life of me figure out how to get autoit to read a line in a text file and give me an array and then be able to let me use each item from the array one after the next. I figured id just try to make a dungeon crawler to refresh myself on what i used to know and learn other stuff in the process. so outside of the context of for a game id still appreciate any help on getting autoit to read a line and then give me a list that i can do if thens with. 

Link to post
Share on other sites

well yeah im not gonna try to automate a game thats been made like wow or something whats the fun in that? you play games to have fun not to have some script play it for you. so far i dont have much script for it because i am stuck on the part where i get the lines to be read. I was able to do it when i had a single number per line but that was just frustrating having to do 1 2 1 2 2 1 2. I am using a code I found to help me get the position of where the Ls and Rs are so that I could then do some if thens with it something like if position 1 is L then blank elseif R then... then if position 3 is L then blank elseif position 3 is R and so on. 

#include <Array.au3>
#include <File.au3>

Local $aInput
$file = "DungeonCrawlerSimulatorv2.txt"



_FileReadToArray($file, $aInput)
For $i = 1 to UBound($aInput) -1
    If $aInput[$i] = 1 Then
        MsgBox (0,'',$aInput[$i])
        Local $iPosition = StringInStr("Dungeon # ", "1")
        MsgBox($MB_SYSTEMMODAL, "", "The search string 'L,' first appears at position: " & $iPosition)

        If $aInput[$i] = "L," Then
        MsgBox (0,'',"Starts with Left")
        EndIf
    EndIf
Next

 

Link to post
Share on other sites

Well I was planning on randomly doing Ls and Rs after the number on each line and then once I figured out how to do two options then work on doing more than two options right now concept wise I'm just working with L is gonna be like a fight or obstacle and R will be a random item. So you could earn XP or you could get like gear or items like HP potion or something that you might have to buy using XP or gold from monsters you beat in the other option. I understand I will have to probably create a GUI at some point so I could click to buy or pass on items or to accept challenge or run.  I only put 5 lines in the Text file going to 10 random directions so there's nothing set in stone atm. Just trying to learn the whole array variables pulling from a string? Then getting the variable. I'm not 100% that these are the first two lines but I can easily change the text to these:

1, L, R, L, R, L, R, L, R, L, R

2, R, R, L, L, R, R, R, L, L, L

 

Unless it would be better for me to do something like:

1LRLRLRLRLR

2RRLLRRRLLL

The only reason I put a number in front is so it would make it easier to test specific lines or to do some sort of find random number between 1-10 later on if I ended up making them more complicated at certain number ranges. I know I know I'm super ambitious but atleast I e got a concept. I just gotta take babysteps.

Link to post
Share on other sites

After reading each line with _FileReadToArray, you could create another array containing each character with StringSplit, so you will have an easy way to scan the content.

Link to post
Share on other sites

I will learn me some StringSplit and report back. Thank you so much. I don't ever expect someone to write code for me I like to learn. I mean unless I write something and you're just like awe buddy that's the hard way then correct me haha. 

Link to post
Share on other sites

Hello.

#include <Debug.au3>

$CtrlFile="C:\temp\Control.txt"
$hCtrlFile=FileOpen($CtrlFile,2+8)
FileWriteLine($hCtrlFile,"1lrlrrrllrlrlr")
FileWriteLine($hCtrlFile,"2rrlrlrllrrrrrllrlrlrllrlrlr")
FileClose($hCtrlFile)

$content=FileRead($CtrlFile)
$ArrayOfChars=StringRegExp($content,"(?i)([lr])",3)
_DebugArrayDisplay($ArrayOfChars)

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...