Jump to content

Variable error when it shouldn't be [RESOLVED]


Recommended Posts

I don't know why, here's the code:

Func Go()
    $MousePos = MouseGetPos()
    If $MousePos[1] < 16 Or $MousePos[1] > 384 Or $MousePos[0] < 16 Or $MousePos[0] > 384 Then
        Sleep(1)
    Else
        GUICtrlSetPos($Player, $MousePos[0] - 16, $MousePos[1] - 16)
    EndIf
    If $MousePos[0] > 318 And $MousePos[1] > 318 Then
        $Lab = GUICtrlCreateLabel("Hello. This is a test message.", 130, 50)
        $Seen = True
    EndIf
    If $MousePos[0] < 318 And $MousePos[1] < 318 And $Seen = True Then
        GUICtrlDelete($Lab)
    EndIf
EndFunc

The variable $Lab is getting the error. $Player and $Talk are icons.

Edited by Minikori

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

My guess is that it's trying to delete the label before it's actually created, I could be wrong but that would be a good start. Try creating the label outside your if statements as transparent/disabled then when the mouse is where you want it show/enable the label.

Link to comment
Share on other sites

  • Moderators

I don't know why, here's the code:

Func Go()
    $MousePos = MouseGetPos()
    If $MousePos[1] < 16 Or $MousePos[1] > 384 Or $MousePos[0] < 16 Or $MousePos[0] > 384 Then
        Sleep(1)
    Else
        GUICtrlSetPos($Player, $MousePos[0] - 16, $MousePos[1] - 16)
    EndIf
    If $MousePos[0] > 318 And $MousePos[1] > 318 Then
        $Lab = GUICtrlCreateLabel("Hello. This is a test message.", 130, 50)
        $Seen = True
    EndIf
    If $MousePos[0] < 318 And $MousePos[1] < 318 And $Seen = True Then
        GUICtrlDelete($Lab)
    EndIf
EndFunc

The variable $Lab is getting the error. $Player and $Talk are icons.

You have $Lab declared only in a conditional statement, if that condition statement ever fails then the variable is not declared.

Edit:

And if the $MousePos[0] < 318 And $MousePos[1] < 318 conditional is ever true, then $Lab could never have a value, because if the before mentioned statement is true, then $MousePos[0] > 318 And $MousePos[1] > 318 is never true.

If you're trying to make $Lab a global, then you need to do so outside the function.

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

My guess is that it's trying to delete the label before it's actually created, I could be wrong but that would be a good start. Try creating the label outside your if statements as transparent/disabled then when the mouse is where you want it show/enable the label.

It shouldn't have to be like that because I added $Seen = True

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Things don't always work the way we think they should. Sm0ke_N had a valid point as well so we're both really saying that you need to declare $Lab outside of your if statements. Try revising your code and see what happens.

Link to comment
Share on other sites

Fixed it, code:

$Main = GUICreate("TestGame", 400, 400)
$Player = GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosaur.ani", -1, 20, 20)
$Talk = GUICtrlCreateIcon("shell32.dll", -197, 350, 350)
$Lab = GUICtrlCreateLabel("Hello. This is a test message.", 130, 50)
GUICtrlSetState($Lab, $GUI_HIDE)

...

Func Go()
    $MousePos = MouseGetPos()
    If $MousePos[1] < 16 Or $MousePos[1] > 384 Or $MousePos[0] < 16 Or $MousePos[0] > 384 Then
        Sleep(1)
    Else
        GUICtrlSetPos($Player, $MousePos[0] - 16, $MousePos[1] - 16)
    EndIf
    If $MousePos[0] > 318 And $MousePos[1] > 318 Then
        GUICtrlSetState($Lab, $GUI_SHOW)
        $Seen = True
    EndIf
    If $MousePos[0] < 318 And $MousePos[1] < 318 And $Seen = True Then
        GUICtrlSetState($Lab, $GUI_HIDE)
        $Seen = False
    EndIf
EndFunc

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Glad you got it working. Please add "[RESOLVED]" to your thread name so that people will know you have it working and anyone with the same type of question can look here and hopefully get an answer a bit more quickly than starting their own thread.

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