Jump to content

Error About Variable Not Declared?


Recommended Posts

Looks pretty declared to me :D

Edit: I know it sais $slot1 = $slot1 + 1, i have to fix that, but that cant be the problem?

$slot1 = 0
$slot2 = 0
$slot3 = 0
$slot4 = 0

<>some script<>

Func _Mana()
    $manacheck = PixelChecksum(729, 586, 731, 588)
    If $manacheck <> $manacompare Then
        If $slot3 < 4 Then
        Send('3')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
    Else
        If $slot4 < 4 Then
        Send('4')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
    EndIf
    EndIf
    EndIf
EndFunc
Edited by Jasio
Link to comment
Share on other sites

  • Moderators

Didn't follow my example real good did you:

Global $slot1 = 0
Global $slot2 = 0
Global $slot3 = 0
Global $slot4 = 0
Global $manacompare
Global $manacheck

;<>some script<>

Func _Mana()
    $manacheck = PixelChecksum(729, 586, 731, 588)
    If $manacheck <> $manacompare Then
        If $slot3 < 4 Then
        Send('3')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
        EndIf
    Else
        If $slot4 < 4 Then
        Send('4')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
        EndIf
    EndIf
EndFunc

You probably need this too after looking at that:

http://www.autoitscript.com/forum/index.php?showtopic=21048

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Didn't follow my example real good did you:

Global $slot1 = 0
Global $slot2 = 0
Global $slot3 = 0
Global $slot4 = 0
Global $manacompare
Global $manacheck

;<>some script<>

Func _Mana()
    $manacheck = PixelChecksum(729, 586, 731, 588)
    If $manacheck <> $manacompare Then
        If $slot3 < 4 Then
        Send('3')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
        EndIf
    Else
        If $slot4 < 4 Then
        Send('4')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
        EndIf
    EndIf
EndFunc

You probably need this too after looking at that:

http://www.autoitscript.com/forum/index.php?showtopic=21048

I followed your example, but what makes no sense is why i have to make it Global? It was working fine without Global on $slot1 and 2. Now that i added 3 and 4 it's telling me that.
Link to comment
Share on other sites

  • Moderators

Besides the function not being correct and the If statements being out of whack, this $manacompare variable was NOT declared at all before you tried to use it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Not working. Still getting undeclared error, heres the script, without the Global for the slots.

Edit: Why are you getting on me for the functions and $mana? they arent my problem, right now its $slot3, and declaring it. Thanks

Global $lifecheck, $lifecompare
AdlibEnable('_Life', 500)
Global $manacheck, $manacompare
AdlibEnable('_Mana', 500)
;HotKeySet( "{END}", "stop" )
;Opt("SendKeyDelay", 1)
;$game = IniRead("DBot.ini", "Info", "gname", "")
;$pass = IniRead("DBot.ini", "Info", "gpass", "")
;$slot = IniRead("DBot.ini", "Info", "gslot", "")
;$account = IniRead("DBot.ini", "Info", "gacct", "")
;$password = IniRead("DBot.ini", "Info", "gpawd", "")
;$num = 1
;$enter = ( "{ENTER}This Program Was Designed By Yasowhat..{ENTER}{ENTER}/DND Away From Keys - B o t t i n g -{ENTER}{ENTER}Enjoy.. Send Comments To D2AccountZ@Hotmail.com..{ENTER}" )
;Run( "C:\Program Files\Diablo II\Diablo II.exe -w -ns" )
;WinWaitActive( "Diablo II" )
;WinActivate( "Diablo II" )
;WinMove( "Diablo II", "", 0, 0 )
;Sleep( 2000 )
;Send( "{ENTER}" )
;MouseClick( "left", 402, 380, 1, 0 )
;Sleep( 15000 )
;Send( $password )
;Send( "{TAB}" )
;Send( $account )
;Send( "{ENTER}" )
;Sleep( 15000 )
;If $slot = "1" Then
;       Mouseclick( "left", 186, 154, 2, 0 )
;   EndIf
;If $slot = "3" Then
;       Mouseclick( "left", 186, 234, 2, 0 )
;   EndIf   
;If $slot = "5" Then
;       Mouseclick( "left", 186, 334, 2, 0 )
;   EndIf
;If $slot = "7" Then
;       Mouseclick( "left", 186, 434, 2, 0 ) 
;   EndIf
;If $slot = "2" Then
;       Mouseclick( "left", 398, 154, 2, 0 )
;   EndIf
;If $slot = "4" Then
;       Mouseclick( "left", 398, 234, 2, 0 )
;   EndIf
;If $slot = "6" Then
;       Mouseclick( "left", 398, 334, 2, 0 )
;   EndIf
;If $slot = "8" Then
;       Mouseclick( "left", 398, 434, 2, 0 )
;   EndIf
Sleep( 3000 )
Sleep( 3000 )
$slot1 = 0
$slot2 = 0
$slot3 = 0
$slot4 = 0
Send("{F3}")
Opt("SendKeyDelay", 1)
WinActivate("Diablo II")
WinWaitActive("Diablo II")
WinMove("Diablo II", "", 0, 0)
Send("{ENTER}")
Sleep(90)
Send("{!}Proceeding To malah{ENTER}")
MouseClick( "left", 9, 265, 1, 0)
Sleep(1200)
Send("{ENTER}")
Sleep(90)
Send("{!}Finding Malah{ENTER}")
While 1
$y = Random( 20, 400 )
$x = Random( 180, 500 )
MouseMove($x, $y, 0)
$malahfind = PixelSearch( 244, 48, 479, 306, 0xFFFFFF, 0, 7  )
If Not @error Then
    MouseClick( "left", $malahfind[0], $malahfind[1] + 10, 1, 0)
    ExitLoop
EndIf
WEnd
MouseMove(0, 0, 0)
Sleep(1000)
Send("{UP}{UP}{ENTER}")
Sleep(1000)
Send("`")
Sleep(100)
While 1
$redcheck = PixelSearch( 425, 494, 455, 526, 0x900000, 0, 1 )
If @error Then
    $redbuy = PixelSearch( 97, 151, 388, 443, 0x900000, 0, 1 )
    MouseClick( "right", $redbuy[0], $redbuy[1], 1, 0)
    Sleep(900)
Else
    ExitLoop
EndIf
WEnd
While 1
$redcheck = PixelSearch( 465, 494, 485, 526, 0x900000, 0, 1 )
If @error Then
    $redbuy = PixelSearch( 97, 151, 388, 443, 0x900000, 0, 1 )
    MouseClick( "right", $redbuy[0], $redbuy[1], 1, 0)
    Sleep(900)
Else
    ExitLoop
EndIf
WEnd
While 1
$bluecheck = PixelSearch( 495, 494, 525, 526, 0x000058, 0, 1 )
If @error Then
    $bluebuy = PixelSearch( 97, 151, 388, 443, 0x000058, 0, 1 )
    MouseClick( "right", $bluebuy[0], $bluebuy[1], 1, 0)
    Sleep(900)
Else
    ExitLoop
EndIf
WEnd
While 1
$bluecheck = PixelSearch( 535, 494, 565, 526, 0x000058, 0, 1 )
If @error Then
    $bluebuy = PixelSearch( 97, 151, 388, 443, 0x000058, 0, 1 )
    MouseClick( "right", $bluebuy[0], $bluebuy[1], 1, 0)
    Sleep(900)
Else
    ExitLoop
EndIf
WEnd
Sleep(400)
$tpbuy = PixelSearch( 97, 151, 388, 443, 0xA0FC88, 0, 1 )
If Not @error Then
    Send("{SHIFTDOWN}")
        MouseClick( "right", $tpbuy[0], $tpbuy[1], 10, 0)
    Send("{SHIFTUP}")
EndIf
Sleep(500)
Send("{ESCAPE}")
Sleep(500)
$finmalclk1 = 406 - $malahfind[0]
$finmalclk2 = 307 - $malahfind[1]
$finmalclkx = 406 + $finmalclk1
$finmalclky = 307 + $finmalclk2
MouseClick( "left", $finmalclkx, $finmalclky, 1, 0)
Send("{ENTER}")
Sleep(90)
Send("Commencing Boss Kill Program{ENTER}")
Sleep(1500)
MouseClick( "left", 793, 266, 1, 0)
Sleep(1500)
MouseClick( "left", 254, 567, 1, 0)
Sleep(2000)
$firecheck = PixelSearch( 250, 422, 500, 580, 0xFCE4A4, 0, 1 )
If Not @error Then
    MouseClick( "left", $firecheck[0], $firecheck[1], 1, 0)
    Send("{ENTER}")
    Sleep(90)
    Send("{!}We Aren't Lost{ENTER}")
EndIf
Sleep(1500)
MouseClick( "left", 182, 218, 1, 0)
Sleep(1500)
$wpcheck = PixelSearch( 150, 450, 300, 580, 0xCCF4F4, 0, 1 )
If Not @error Then
    MouseClick( "left", $wpcheck[0], $wpcheck[1], 1, 0)
EndIf
Sleep(1500)
MouseClick( "left", 244, 450, 1, 0)
Sleep(1500)
Send("{F4}")
MouseClick("right", 100, 100, 1, 0)
Sleep(700)
Send("w")
Sleep(700)
Send("{F5}")
MouseClick("right", 100, 100, 1, 0)
Sleep(700)
Send("{F6}")
MouseClick("right", 100, 100, 1, 0)
Sleep(700)
Send("w")
Sleep(700)
Send("{F3}")
Sleep(1500)
MouseClick( "left", 410, 310, 1, 0)
Sleep(1000)
MouseClick( "left", 199, 170, 1, 0)
Sleep(1000)
$harrocheck = PixelSearch( 251, 157, 288, 195, 0x883024, 0, 1 )
If Not @error Then
    MouseClick( "left", $harrocheck[0] -75, $harrocheck[1] + 400, 1, 0)
EndIf
Sleep(1500)
$firecheck = PixelSearch( 90, 460, 184, 546, 0xFCE4A4, 0, 1 )
If Not @error Then
    MouseClick( "left", $firecheck[0] + 75, $firecheck[1] + 55, 1, 0)
    Send("{ENTER}")
    Sleep(90)
    Send("{!}Sorry Pindle </3{ENTER}")
EndIf
Sleep(1500)
MouseClick( "left", 74, 317, 1, 0)
Sleep(1500)
$anporcheck = PixelSearch( 200, 50, 450, 200, 0xFC2C00, 0, 1 )
If Not @error Then
    MouseClick( "left", $anporcheck[0], $anporcheck[1] + 25, 1, 0)
    Send("{ENTER}")
    Sleep(90)
    Send("{!}The Only Reason This Bot Talks Is Because I Was Lonely When I Made It{ENTER}")
EndIf
Send("{F1}")
Sleep(1500)
MouseClick( "right", 631, 84, 1, 0)
Sleep(1000)
MouseClick( "right", 652, 101, 1, 0)
Sleep(1000)
MouseClick( "right", 696, 142, 1, 0)
Sleep(1000)
MouseClick( "right", 603, 204, 1, 0)
Sleep(1000)
MouseClick( "right", 692, 161, 1, 0)
Sleep(800)
Send("{F2}{SHIFTDOWN}")
MouseClick("left", 100, 100, 1, 0)
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Send("{F1}")
MouseClick( "right", 682, 151, 1, 0)
Send("{F2}")
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Send("{F1}")
MouseClick( "right", 672, 141, 1, 0)
Send("{F2}")
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Sleep(800)
MouseClick("left", 100, 100, 1, 0)
Func stop()
    Exit
EndFunc
Func _Life()
    $lifecheck = PixelChecksum(73, 586, 731, 588)
    If $lifecheck <> $lifecompare Then
        If $slot1 < 4 Then
        Send('1')
        $lifecompare = $lifecheck
        $slot1 = $slot1 + 1
        Sleep(2000)
    Else
        If $slot2 < 4 Then
        Send('2')
        $lifecompare = $lifecheck
        $slot2 = $slot2 + 1
        Sleep(2000)
    EndIf
    EndIf
    EndIf
EndFunc
Func _Mana()
    $manacheck = PixelChecksum(729, 586, 731, 588)
    If $manacheck <> $manacompare Then
        If $slot3 < 4 Then
        Send('3')
        $manacompare = $manacheck
        $slot3 = $slot3 + 1
        Sleep(2000)
    Else
        If $slot4 < 4 Then
        Send('4')
        $manacompare = $manacheck
        $slot4 = $slot4 + 1
        Sleep(2000)
    EndIf
    EndIf
    EndIf
EndFunc
Edited by Jasio
Link to comment
Share on other sites

  • Moderators

Blah... I tell you what... Go read the help file on Declaring Variables (Global/Local/Dim) when you understand what they mean you'll fix your own issue. I told you what was wrong.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

? I used Globals, and i had the same error. Whats the point in sending me in circles when you probably know what to do?

Because the answer was given to you in the very first post, it isn't just your variables not being declared,.
Global $slot1 = 0
Global $slot2 = 0
Global $slot3 = 0
Global $slot4 = 0
Global $manacompare
Global $manacheck

;<>some script<>

Func _Mana()
    $manacheck = PixelChecksum(729, 586, 731, 588)
    If $manacheck <> $manacompare Then
        If $slot3 < 4 Then
        Send('3')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
        EndIf
    Else
        If $slot4 < 4 Then
        Send('4')
        $manacompare = $manacheck
        $slot1 = $slot1 + 1
        Sleep(2000)
        EndIf
    EndIf
EndFunc
Throws 0 errors. Stop being hard headed... Your If statements were wrong your function wasn't finished and your variables were not declared, look at the example I provided and re-structure your code... I don't know how much more DIRECT I CAN BE.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I'm hardheaded? used your code

C:\Documents and Settings\Owner\Desktop\dbot\D2Bot.au3 (267) : ==> Variable used without being declared.:

lol... yes you are hard headed, but that's not always a bad thing. My code "STRUCTURE" is fine, although I should have made it an ElseIf rather than an Else / If ... I checked it for errors in SciTe before I pasted it. Now, it by itself, may not work, because you also have an issue of the same thing in the function above it.

Download Scite, run Tidy from the tools menu. You should see where all your errors are. This is me helping you to help yourself.... Take it as rude if you like, but I'm not going to re-write the code for you, you need to do that on your own. I've told you the issues, but SciTe would be good, because it could comment in all the areas your having issues in.

http://www.autoitscript.com/forum/index.php?showtopic=28210

Edit:

You also can't have 2 AdlibEnables() like that... they would need to be structured differently... something like:

AdlibEnable('_AdlibManager', 500)

While 1
;script
WEnd

Func _AdlibManager()
    _Life()
    _Mana()
EndFunc

Func _Life()
;function script
EndFunc

Func _Mana()
;function script
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Just put something there that resets them when you restart the loop :D

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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