Jump to content

Loops Bug


Dieuz
 Share

Recommended Posts

Hi there!

I'm having a little problem with a part of my script

For ???????????????????
    
$ColorAttack = Pixelgetcolor(840,467)
$ColorVictory = Pixelgetcolor(507,457)
    
If $ColorAttack ="5902484" Then
MouseClick ( "left" , 505, 455 , 1 , 1  )

ElseIf $ColorVictory ="15716261" Then
MouseClick ( "left" , 512, 530 , 1 , 1  )
sleep(2000)
Call ("Winner")

Endif
Next

I want the script to loop but I dont know what to write after For. I tried with $n = 1 to $ColorAttack and the script worked fine for the first part but when it should have launched the ElseIf , nothing happened.

Thanks alot!

Link to comment
Share on other sites

How many times do you want this to loop? A For...Next loop will execute however many times you specify. If you want the script to loop indefinitely try wrapping it in:

While 1
    ;stuff here
WEnd
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Well it loop alot of time until it suppose to reach my ElseIf ( when a new windows pop up). It loops like 10-15 time before it supposed to reach the ElseIf.

I tried with While 1 and Wend but the ElseIf is suppose to work, nothing happened. Maybe the problem come from there...

CODE
CODE
While 1

$ColorAttack = Pixelgetcolor(840,467)

$ColorVictory = Pixelgetcolor(507,457)

If $ColorAttack ="5902484" Then

MouseClick ( "left" , 505, 455 , 1 , 1 )

ElseIf $ColorVictory ="15716261" Then

MouseClick ( "left" , 512, 530 , 1 , 1 )

sleep(2000)

Call ("Winner")

Endif

Wend

Edited by Dieuz
Link to comment
Share on other sites

Perhaps a Do...Until loop would better suit your needs. The examples in the helpfile show how each loop can be utilized.

Do    
    $ColorAttack = Pixelgetcolor(840,467)
    $ColorVictory = Pixelgetcolor(507,457)      
    If $ColorAttack ="5902484" Then MouseClick ( "left" , 505, 455 , 1 , 1  )
Until $ColorVictory ="15716261"
MouseClick ( "left" , 512, 530 , 1 , 1  )
sleep(2000)
Call ("Winner")

Is that more like what you are trying to do?

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Yes I want something like this. I tried your code but the same thing happened again, the ElseIf doesnt work...

First of all, there are no ElseIfs in the snippet I posted. Secondly, just saying something "doesn't work" is useless. If you want more help, you're going to have to explain what is happening, ie. describe what you expect to happen and the errors you are getting. Perhaps your color code is incorrect.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

New Issue: Count Variable

I want to set a splash text everytime my character won a combat and the numbers on the splash text will change. The number will change everytime the script reach this point. Wich variables should I use to achieve that? The variable start at 0 have to change +1 each time.

$TimesWon = 

; Displays a splash text to show the number of combats won
SplashTextOn ("", "Combats Won: $TimesWon" , 290, 20, 0, 30, 1, "", 10)
Edited by Dieuz
Link to comment
Share on other sites

  • Developers

$TimesWon = 0
;
;
;
; Displays a splash text to show the number of combats won
$TimesWon += 1
SplashTextOn ("", "Combats Won: " & $TimesWon , 290, 20, 0, 30, 1, "", 10)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

$TimesWon = 0
;
;
;
; Displays a splash text to show the number of combats won
$TimesWon += 1
SplashTextOn ("", "Combats Won: " & $TimesWon , 290, 20, 0, 30, 1, "", 10)
I tried your code and Im getting this error:

C:\Documents and Settings\XXXXX : ==> Expected a "=" operator in assignment statement.: 
$Trophyswon += 1 
$Trophyswon ^ ERROR

My script close instantly.

Anyone else know how to set my splash text? The variable start at 0 and +1 is added everytime the script pass over it.

Edited by Dieuz
Link to comment
Share on other sites

  • Developers

What version of AutoIt3 are you using ?

On older versions:

$Trophyswon = $Trophyswon + 1

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks , it's working ! I have an older version, I will upgrade it.

Quick question: What is the operator used to express " is not equal to"?

I tried with $ColorBug NOT "7567456" but im getting an error.

Edited by Dieuz
Link to comment
Share on other sites

I made some tests and found that finally it wasnt working.

The number always stay 1 because:

$Trophyswon =0

$Trophyswon = $Trophyswon + 1 
SplashTextOn ("", "Combats Won: " & $TimesWon , 290, 20, 0, 30, 1, "", 10)

It's always 0 +1, so always 1. $Trophyswon should add + 1 everytime the script pass this code but now it isnt.

Example of what I want:

First time the script reach this part : $Trophyswon = 1

Second time the script reach this part : $Trophyswon = 2

Third time the script reach this part : $Trophyswon = 3

Fourth time the script reach this part : $Trophyswon = 4

etc...

Edited by Dieuz
Link to comment
Share on other sites

  • Developers

I made some tests and found that finally it wasnt working.

The number always stay 1 because:

$Trophyswon =0

$Trophyswon = $Trophyswon + 1 
SplashTextOn ("", "Combats Won: " & $TimesWon , 290, 20, 0, 30, 1, "", 10)
oÝ÷ ØwöÆ¥Á¬¬Óíl¡©pk+5Ó~®aÊÌ(ÈhºWZußµz÷«ÊئzØ^±Êâ¦ÚZ²ËaÇ(uæî¶z0جÑ1jjezð«HÁ©í*ì¶Ø¦zØ^±Êâ¦ÚÞiÈm+)j»tߤë¢r³
'
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I know, I have 150 lines of script. I put it somewhere in my script but everytime the script pass over it, the number stay 1. It's why im wondering if this code is correct.

Yea guess my code is wrong somewhere ... :P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yea guess my code is wrong somewhere ... :P

OK smartguy, You made me take a second look. I should have known better but for a split second I thought maybe it was you tha put the $Trophyswon = 0 inside the loop. In that case of course $Trohpyswon would always = 1. :D

Time to take a break. If I was a drinking man I'd have a stiff belt right about now.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Ok I feel stupid because I cant correct this simple problem. Have a look at my core script and see if you can find where's the problem come from.

;Hotkeys
HotKeySet("{HOME}", "Terminate") ;
HotKeySet("{F2}", "Start") ; 
HotKeySet("{F4}", "Pause") ; 

;Variables

Global $Paused
$ColorAttack = Pixelgetcolor(837,464)
$ColorVictory = Pixelgetcolor(402,169)
$Color5wins = Pixelgetcolor(595,387)
$Trophyswon = 0
$ColorBug = Pixelgetcolor(840,467)



While 1
    sleep(100)
Wend

Func Start()

;Stuff here

Call ("Restart")
EndFunc

Func Restart()
    
;Stuff here

;5 WINS
If $Color5wins ="5911585" Then
    Call ("Winner")

;Stuff here

Call ("Restart")
EndFunc



Func Winner()

;stuff here
        
$Trophyswon = $Trophyswon + 1 
SplashTextOn ("", "Trophys Won: " & $Trophyswon, 290, 20, 0, 30, 1, "", 10) 

;stuff here

Call ("Restart")
EndFunc

Func Pause()

;stuff here
    
EndFunc

Func Terminate()
  Exit(0)
  EndFunc

With this script, im always getting $Trohpyswon=1

Edited by Dieuz
Link to comment
Share on other sites

Ok I feel stupid because I cant correct this simple problem. Have a look at my core script and see if you can find where's the problem come from.

;Hotkeys
HotKeySet("{HOME}", "Terminate") ;
HotKeySet("{F2}", "Start") ; 
HotKeySet("{F4}", "Pause") ; 

;Variables

Global $Paused
$ColorAttack = Pixelgetcolor(837,464)
$ColorVictory = Pixelgetcolor(402,169)
$Color5wins = Pixelgetcolor(595,387)
$Trophyswon = 0
$ColorBug = Pixelgetcolor(840,467)
While 1
    sleep(100)
Wend

Func Start()

;Stuff here

Call ("Restart")
EndFunc

Func Restart()
    
;Stuff here

;5 WINS
If $Color5wins ="5911585" Then
    Call ("Winner")

;Stuff here

Call ("Restart")
EndFunc
Func Winner()

;stuff here
        
$Trophyswon = $Trophyswon + 1 
SplashTextOn ("", "Trophys Won: " & $Trophyswon, 290, 20, 0, 30, 1, "", 10) 

;stuff here

Call ("Restart")
EndFunc

Func Pause()

;stuff here
    
EndFunc

Func Terminate()
  Exit(0)
  EndFunc

With this script, im always getting $Trohpyswon=1

a splash won't update automatically

$Trophyswon = $Trophyswon + 1

SplashTextOn ("", "Trophys Won: " & $Trophyswon, 290, 20, 0, 30, 1, "", 10)

See ControlSetText in the help file under Window Management / Controls

Doing it without ControlSetText tou would hve to do

SplashTextOn ("", "Trophys Won: " & $Trophyswon, 290, 20, 0, 30, 1, "", 10)

Sleep(5000) ;; Use a time long enough to read the message and then shut it off.

SplashOff()

You are better off with ControlSetText.

A better answer yet is to get rid of the Splash altogether and create a GUI the same size as your splash. Then create a lable the full size of the gui. With that arrangement you could use

$Trophyswon = $trophyswon +1

GuiCtrlSetData($my_Label("Trophies won " & $Trophyswon)

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...