Jump to content

Trying to avoid recursion - Code Flow Help


Wizzel
 Share

Recommended Posts

Hi. I am a bit confused about making the flow of my code work. I could put everything into functions and have them call eachother, but I know that would eventually cause a recursion. Basically, I need it to go through a series of tests and procedures.

CODE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.11.0 (beta)

Author: Wizzel

Script Function:

None Yet =p

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <IE.au3>

$check = 1

While $check = 1

$sText = _IEBodyReadText($oIE)

If StringInStr($sText, "food") Then

;;; I found it

$check = 0

$buy = 1

Else

;MsgBox(4096, "Test", "We are not in the food market")

_IENavigate ($oIE, "www.google.com")

_IELoadWait ($oIE)

EndIf

Wend

While $buy = 1

_IELoadWait ($oIE)

MouseClickDrag("left", 516, 714, 538, 714) ; copies the text in question (taht you painted blue with clickdrag)

Send("^c") ; sends ctrl+c (copy to clip)

$pricebuy = ClipGet() ; sets variable $clip to "copied text"

;MsgBox(4096, "Buycheck1 Debug", $pricebuy)

$buy = 2

Wend

While $buy = 2

If $pricebuy > 40 Then

; MsgBox(4096, "Buycheck2 Debug", "This is not a good purchase!")

_IEAction($oIE, "refresh")

$buy = 0

$check = 1

Else

;MsgBox(4096, "Buycheck2 Debug", "This is a good purchase!")

$buy = 1

$check = 0

EndIf

Wend

While $buy = 1

MsgBox(4096, "Buycheck2 Debug", "Buying!")

Wend

Anyway, it may make no sense but it works great for the task I am doing. Basically, when it finds its not a good purchase, and then sets $check = 1 in hopes it will go back to the top of the script and see that $check = 1 and then refresh and test again, kind of like a loop. But it just goes down and ends. Any ideas? Am I coding a weird way? let me know.

My idea:

URL check, if passes, then go to price check, go to the URL agan

Price Check

If price is too high, go back to URL check, if it is perfect, buy.

Edited by Wizzel
Link to comment
Share on other sites

I don't have time to test it but a quick look : I don't think this lines ever works for you does it? you never get there.

While $buy = 1
MsgBox(4096, "Buycheck2 Debug", "Buying!")
Wend
You are correct. That was a mistake. But I am more looking for an better way to code a series of steps that will perform a task of buying and selling. I am looking to code these without functions, because I don't want to cause a recursion. I have been down that path before :). While loops work well but lets say further down, I want to declare $check = 1. It won't go back to the beginning and find the While $check = 1. It goes to the end and stops. I must be organizing this wrong. Thanks.

Anyone have any ideas.

Edited the code btw to fix that error mentioned here.

Link to comment
Share on other sites

You are correct. That was a mistake. But I am more looking for an better way to code a series of steps that will perform a task of buying and selling. I am looking to code these without functions, because I don't want to cause a recursion. I have been down that path before :). While loops work well but lets say further down, I want to declare $check = 1. It won't go back to the beginning and find the While $check = 1. It goes to the end and stops. I must be organizing this wrong. Thanks.

Anyone have any ideas.

Edited the code btw to fix that error mentioned here.

your solution is : "Switch", "Select" and "Case" read about them. have fun.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...