SimpleMindedFool Posted November 2, 2006 Posted November 2, 2006 First, HUGE thanks to you folks for AutoIt and the AutoIt forums I'm at line 767 on my first program and this is only the second time I've gotten stuck. This is the first time something isn't working the way I thought it would, so I need a little guidance. (Be Gentle) I am getting an error "Can not redeclare a constant", but there are ONLY two instances of each of the two Constants in the file. Here are the snippets from my code ;declared constant Global const $BlockH = 11, $BlockW = 16 ;fill variables with constant values $BlkH=$BlockH $BlkW=$BlockW ;these are the lines I am performing that reference the variables While 1 If _IsPressed("01") Then $LastLeftClick=MouseGetPos() ToolTip("LeftClick: "&$LastLeftClick[0]&","&$LastLeftClick[1],1100,600) ExitLoop EndIf WEnd MouseMove($LastLeftClick[0],$LastLeftCLick[1]-$BlkH,10) Send($keyL) $PieceIsGood= PixelSearch($LastLeftClick[0]-$BlkW,$LastLeftCLick[1]-$BlkH,$LastLeftClick[0]+$BlkW,$LastLeftCLick[1]+$BlkH,$badBridge) if @error then Beep(1000,500) $DeadEnd=1 EndIf MouseClick("left",$LastLeftClick[0],$LastLeftCLick[1]-$BlkH,10) Sleep(1000) ;the error kicks me out somewhere in the above code I think it may be due to my addition of an array with a constant, but not sure how else to do this. I just don't understand why the "redeclare" error is popping up, cause I don't think I'm redeclaring the constant. Thanks in advance If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
Moderators SmOke_N Posted November 2, 2006 Moderators Posted November 2, 2006 ;declared constant Global const $BlockH = 11, $BlockW = 16 ;fill variables with constant values $BlkH=$BlockH $BlkW=$BlockWOnce you make a constant, you can't change it (thus it being a constant)You see here that you try to make the constant = $BlockH and $BlockW (not thinking I like the sounds of those vars too much). Just remove the word Constant. 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.
buzz44 Posted November 2, 2006 Posted November 2, 2006 (edited) $BlkH / $BlkW arn't constants but, and hes not changing the values of $BlockH or $BlockW. Edited November 2, 2006 by Burrup qq
Moderators SmOke_N Posted November 2, 2006 Moderators Posted November 2, 2006 $BlkH / $BlkW arn't constants but, and hes not changing the values of $BlockH or $BlockW.Oops :"> (totally misread that) 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.
buzz44 Posted November 2, 2006 Posted November 2, 2006 , what line number does it indicate the error is on SimpleMindedFool? qq
SimpleMindedFool Posted November 2, 2006 Author Posted November 2, 2006 ;declared constant Global const $BlockH = 11, $BlockW = 16 ;fill variables with constant values $BlkH=$BlockH $BlkW=$BlockWOnce you make a constant, you can't change it (thus it being a constant)You see here that you try to make the constant = $BlockH and $BlockW (not thinking I like the sounds of those vars too much). Just remove the word Constant. Thanks for the quick reply! I WANT these variables to be Constant. I added the $BlkH and $BlkW in an attempt to protect the constants. (Apparently it didn't work) Where is the line(s) that is(are) trying to change them? BTW, the Vars are refering to pixel blocks ... 11 pixels high by 16 pixels wide, not sure why you don't like the sound. But I am declaring them early, so I can adjust them later if my calculations are wrong. The code lines where this is crashing is going to be used in a Select-Case-EndSelect in each of the Cases (27 so far). Thanks in advance. If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
SimpleMindedFool Posted November 2, 2006 Author Posted November 2, 2006 , what line number does it indicate the error is on SimpleMindedFool? Line 105, which reads: Global const $BlockH = 11, $BlockW = 16 This is the only declaration for these, too. If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
buzz44 Posted November 2, 2006 Posted November 2, 2006 (edited) Thanks for the quick reply! I WANT these variables to be Constant. But I am declaring them early, so I can adjust them later if my calculations are wrong.If your going to change them later why make them constants @@? Do you need to "protect" the original 16 and 11 values? If your not going to change the variables (meaning your calculations are correct), and not have them constant, just don't use them. Edit: Can you declare 2 variables on the same line in AutoIt? (I forget ). Perhaps... Global Const $BlockH = 11 Global Const $BlockW = 16 Edited November 2, 2006 by Burrup qq
SimpleMindedFool Posted November 2, 2006 Author Posted November 2, 2006 If your going to change them later why make them constants @@? Do you need to "protect" the original 16 and 11 values? If your not going to change the variables (meaning your calculations are correct), and not have them constant, just don't use them. Edit: Can you declare 2 variables on the same line in AutoIt? (I forget ). Perhaps... Global Const $BlockH = 11 Global Const $BlockW = 16 Sorry, must clarify... I want $BlockW and $BlockH to be constant. These may need adjustment, but not during program operation (sort of a tweaking point at the code level). $BlkH and $BlkW were introduced because I was getting the redefine error. The idea was to isolate the Constants by using a substitute variable instead. If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
SimpleMindedFool Posted November 2, 2006 Author Posted November 2, 2006 Can you declare 2 variables on the same line in AutoIt? (I forget ). Perhaps... Global Const $BlockH = 11 Global Const $BlockW = 16 According to help, yes. But tried it on seperate lines and it kicks out on first line: Global const $BlockH = 11 Global Const $BlockW = 16 If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
buzz44 Posted November 3, 2006 Posted November 3, 2006 And your SURE your not declaring $BlockH anywhere else? qq
SimpleMindedFool Posted November 3, 2006 Author Posted November 3, 2006 And your SURE your not declaring $BlockH anywhere else? I search the code several times, only two instances of each of the Constants listed. I even used the I also checked the "#include" files for the variable name, just in case. By trial and error method (comment out line by line), I have found the following section is the guilty offender: $PieceIsGood= PixelSearch($LastLeftClick[0]-$BlkW, $LastLeftCLick[1]-$BlkH, $LastLeftClick[0]+$BlkW, $LastLeftCLick[1]+$BlkH, $badBridge) if @error then Beep(1000,500) $DeadEnd=1 EndIf When I change the "if @error" to "if NOT @error", I don't get the redefine error. However, I also don't get the correct response from the argument. I don't think PixelSearch likes my "mixed" array and variable additions. The coords are correct (triple checked) and the color is correct. The purpose is to check around the current mouse position for a specific color and if found, set a flag ($DeadEnd) so it will drop out of the loop. Is there an easy way to store one piece of an array into a single variable? For example, how would make the following code work? $LastLeftClick=MouseGetPos() $LastX=$LastLeftClick[0] $LastY=$LastLeftClick[1] If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
buzz44 Posted November 3, 2006 Posted November 3, 2006 That is the easiest way, and that SHOULD work. Is $DeadEnd a constant? qq
SimpleMindedFool Posted November 3, 2006 Author Posted November 3, 2006 (edited) That is the easiest way, and that SHOULD work. Is $DeadEnd a constant?No, $DeadEnd is a local variable, not constant. In fact the only Constants in the whole code are the two mentioned before. And FYI, when the two Global Const are reversed, the other one gets redefine error. Also moving "Global Const" above all other "Global" (above all declaration line in fact) had not effect. All goes back to my screwball PixelSearch with the if @error, instead of if NOT @error ... easiest way, and SHOULD work? ... hmmm ... where's the dunce cap smilie for me? I'm going to wrestle around with this some more, but I think I might be going in the right direction. I really appreciate the help. Edit: I was wrong, sort of ... $DeadEnd is a local variable ... but in my use it became a Constant: Do ;snip - snip $DeadEnd=1 ;snip - snip while $DeadEnd=0 I still can't figure out why it was kicking me back to the first "Global Const" definition line. That confused me ... which isn't too hard to do Edited November 3, 2006 by SimpleMindedFool If I learned from all my mistakes, I would be the smartest man alive!Nothing is fool-proof, because fools are so ingenious.Ingorance it not knowing better. Stupidity is knowing better, but doing it anyway. No way can I be stupid.
buzz44 Posted November 3, 2006 Posted November 3, 2006 So you fixed it? I think the AutoIt "IDE" is alot like most C++ IDE's, which can give you misleading errors, specially if you miss a semi-colon . qq
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now