 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Eedis NLI Guest
|
Posted: Fri Jan 15, 2010 3:30 am Post subject: If statement not working. |
|
|
I'm trying to get two random numbers and put them into the variables A and B. Then I have an IF statement to tell me if A=B, if not then it tells me it doesn't. I have a MsgBox to debug my code so I can physically see if A=B myself, but the program ALWAYS says that A=B, even if they don't.
*NOTE* For easier explanation, I used A and B in explanation instead of the real variables used in the program.
| Code: | Loop
{
msgbox, %11% - %12%
if (%12% = %11%)
{
Msgbox, 11=12
random, 12, 1, 9
}
if (%12% <> %11%)
{
msgbox, Not same.
Break
}
} |
|
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Fri Jan 15, 2010 3:42 am Post subject: |
|
|
| Quote: | | Variable names in an expression are not enclosed in percent signs (except for arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables. |
so you cannot have variables named with only numbers because then it thinks they are numbers not variables.
this works
| Code: | Loop
{
random, a, 1, 9
random, b, 1, 9
msgbox, %a%, %b%
if (a = b)
{
msgbox, same.
Break
}
} |
|
|
| Back to top |
|
 |
Eedis
Joined: 12 Jun 2009 Posts: 1158 Location: Indianapolis IN, USA
|
Posted: Fri Jan 15, 2010 3:49 am Post subject: |
|
|
Well, let me post my whole code on here. It's supposed to generate a complete sudoku board.
| Code: | loop 9
{
x1=%a_index%
loop 9
{
x2=%A_index%
gosub, rannum
if (x1 = 1 AND x2 = 2)
{
Loop
{
msgbox, Still in loop.`n%11% - %12%
if (%12% = %11%)
{
Msgbox, 11=12
gosub, rannum
}
if (%12% <> %11%)
{
msgbox, Not same.
Break
}
}
}
}
}
Gui, Add, Text, x20 y20 w15 h15 , %11%
Gui, Add, Text, x50 y20 w15 h15 , %12%
Gui, Add, Text, x80 y20 w15 h15 , %13%
Gui, Add, Text, x110 y20 w15 h15 , %14%
Gui, Add, Text, x140 y20 w15 h15 , %15%
Gui, Add, Text, x170 y20 w15 h15 , %16%
Gui, Add, Text, x200 y20 w15 h15 , %17%
Gui, Add, Text, x230 y20 w15 h15 , %18%
Gui, Add, Text, x260 y20 w15 h15 , %19%
Gui, Add, Text, x20 y50 w15 h15 , %21%
Gui, Add, Text, x50 y50 w15 h15 , %22%
Gui, Add, Text, x80 y50 w15 h15 , %23%
Gui, Add, Text, x110 y50 w15 h15 , %24%
Gui, Add, Text, x140 y50 w15 h15 , %25%
Gui, Add, Text, x170 y50 w15 h15 , %26%
Gui, Add, Text, x200 y50 w15 h15 , %27%
Gui, Add, Text, x230 y50 w15 h15 , %28%
Gui, Add, Text, x260 y50 w15 h15 , %29%
Gui, Add, Text, x20 y80 w15 h15 , %31%
Gui, Add, Text, x50 y80 w15 h15 , %32%
Gui, Add, Text, x80 y80 w15 h15 , %33%
Gui, Add, Text, x110 y80 w15 h15 , %34%
Gui, Add, Text, x140 y80 w15 h15 , %35%
Gui, Add, Text, x170 y80 w15 h15 , %36%
Gui, Add, Text, x200 y80 w15 h15 , %37%
Gui, Add, Text, x230 y80 w15 h15 , %38%
Gui, Add, Text, x260 y80 w15 h15 , %39%
Gui, Add, Text, x20 y110 w15 h15 , %41%
Gui, Add, Text, x50 y110 w15 h15 , %42%
Gui, Add, Text, x80 y110 w15 h15 , %43%
Gui, Add, Text, x110 y110 w15 h15 , %44%
Gui, Add, Text, x140 y110 w15 h15 , %45%
Gui, Add, Text, x170 y110 w15 h15 , %46%
Gui, Add, Text, x200 y110 w15 h15 , %47%
Gui, Add, Text, x230 y110 w15 h15 , %48%
Gui, Add, Text, x260 y110 w15 h15 , %49%
Gui, Add, Text, x20 y140 w15 h15 , %51%
Gui, Add, Text, x50 y140 w15 h15 , %52%
Gui, Add, Text, x80 y140 w15 h15 , %53%
Gui, Add, Text, x110 y140 w15 h15 , %54%
Gui, Add, Text, x140 y140 w15 h15 , %55%
Gui, Add, Text, x170 y140 w15 h15 , %56%
Gui, Add, Text, x200 y140 w15 h15 , %57%
Gui, Add, Text, x230 y140 w15 h15 , %58%
Gui, Add, Text, x260 y140 w15 h15 , %59%
Gui, Add, Text, x20 y170 w15 h15 , %61%
Gui, Add, Text, x50 y170 w15 h15 , %62%
Gui, Add, Text, x80 y170 w15 h15 , %63%
Gui, Add, Text, x110 y170 w15 h15 , %64%
Gui, Add, Text, x140 y170 w15 h15 , %65%
Gui, Add, Text, x170 y170 w15 h15 , %66%
Gui, Add, Text, x200 y170 w15 h15 , %67%
Gui, Add, Text, x230 y170 w15 h15 , %68%
Gui, Add, Text, x260 y170 w15 h15 , %69%
Gui, Add, Text, x20 y200 w15 h15 , %71%
Gui, Add, Text, x50 y200 w15 h15 , %72%
Gui, Add, Text, x80 y200 w15 h15 , %73%
Gui, Add, Text, x110 y200 w15 h15 , %74%
Gui, Add, Text, x140 y200 w15 h15 , %75%
Gui, Add, Text, x170 y200 w15 h15 , %76%
Gui, Add, Text, x200 y200 w15 h15 , %77%
Gui, Add, Text, x230 y200 w15 h15 , %78%
Gui, Add, Text, x260 y200 w15 h15 , %79%
Gui, Add, Text, x20 y230 w15 h15 , %81%
Gui, Add, Text, x50 y230 w15 h15 , %82%
Gui, Add, Text, x80 y230 w15 h15 , %83%
Gui, Add, Text, x110 y230 w15 h15 , %84%
Gui, Add, Text, x140 y230 w15 h15 , %85%
Gui, Add, Text, x170 y230 w15 h15 , %86%
Gui, Add, Text, x200 y230 w15 h15 , %87%
Gui, Add, Text, x230 y230 w15 h15 , %88%
Gui, Add, Text, x260 y230 w15 h15 , %89%
Gui, Add, Text, x20 y260 w15 h15 , %91%
Gui, Add, Text, x50 y260 w15 h15 , %92%
Gui, Add, Text, x80 y260 w15 h15 , %93%
Gui, Add, Text, x110 y260 w15 h15 , %94%
Gui, Add, Text, x140 y260 w15 h15 , %95%
Gui, Add, Text, x170 y260 w15 h15 , %96%
Gui, Add, Text, x200 y260 w15 h15 , %97%
Gui, Add, Text, x230 y260 w15 h15 , %98%
Gui, Add, Text, x260 y260 w15 h15 , %99%
Gui, Font, S14 bold CGreen, Verdana
Gui, Add, Text, x20 y285 w15 h20 , 1
Gui, Add, Text, x50 y285 w15 h20 , 2
Gui, Add, Text, x80 y285 w15 h20 , 3
Gui, Add, Text, x110 y285 w15 h20 , 4
Gui, Add, Text, x140 y285 w15 h20 , 5
Gui, Add, Text, x170 y285 w15 h20 , 6
Gui, Add, Text, x200 y285 w15 h20 , 7
Gui, Add, Text, x230 y285 w15 h20 , 8
Gui, Add, Text, x260 y285 w15 h20 , 9
Gui, Show,, E-doku
Return
rannum:
random, %x1%%x2%, 1, 2
Return
GuiClose:
ExitApp |
_________________ www.AutoHotkey.net/~Eedis
I love my wife and daughter so much.
 |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Fri Jan 15, 2010 4:05 am Post subject: |
|
|
| Code: | 11=2
12=2
Loop
{
msgbox, %11% - %12%
a=%11%
b=%12%
if (a = b)
{
Msgbox, 11=12
random, 12, 1, 9
b=%12%
}
if (a <> b)
{
msgbox, Not same.
Break
}
} |
I made it copy 11 and 12 to temporary variables for the comparisons |
|
| Back to top |
|
 |
jarhed Guest
|
|
| Back to top |
|
 |
Eedis
Joined: 12 Jun 2009 Posts: 1158 Location: Indianapolis IN, USA
|
Posted: Fri Jan 15, 2010 4:12 am Post subject: |
|
|
Just tried this and it didn't work, same results. | Code: | loop 9
{
x1=%a_index%
loop 9
{
x2=%A_index%
gosub, rannum
if (x1 = 1 AND x2 = 2)
{
Loop
{
a=%11%
b=%12%
msgbox, Still in loop.`n%a% - %b%
if (%a% = %b%)
{
Msgbox, 11=12
gosub, rannum
}
if (%a% <> %b%)
{
msgbox, Not same.
11=%a%
12=%a%
Break
}
}
}
}
} |
_________________ www.AutoHotkey.net/~Eedis
I love my wife and daughter so much.
 |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Fri Jan 15, 2010 4:34 am Post subject: |
|
|
| Quote: | | not enclosed in percent signs |
|
|
| Back to top |
|
 |
jarhed Guest
|
Posted: Fri Jan 15, 2010 4:34 am Post subject: |
|
|
stop guessing and do some studing.
Read this (especially sections H and I). Then apply what you have learned.
AutoHotkey Expression Examples: "" %% () and all that.
start with some simple testing!!
| Quote: | a = 2
b = 3
if (%a% <> %b%)
msgbox, different
else
msgbox, same
exitapp |
Why does this code report that a is equal to b?
Read the link I gave, then modify this code to produce the correct results.
Don't expect help if you are not willing to expend some effort learning.  |
|
| Back to top |
|
 |
Eedis
Joined: 12 Jun 2009 Posts: 1158 Location: Indianapolis IN, USA
|
Posted: Fri Jan 15, 2010 4:37 am Post subject: |
|
|
Well, in all honesty, I do put effort into learning it and would rather learn it than anything else. It's just right now, I'm doing a lot of other things, so I'm more or less fiddling with it at the moment until I get free time to actually study it and read up on it. There is no harm in that. _________________ www.AutoHotkey.net/~Eedis
I love my wife and daughter so much.
 |
|
| Back to top |
|
 |
BoffinbraiN
Joined: 16 Nov 2009 Posts: 114
|
Posted: Fri Jan 15, 2010 2:10 pm Post subject: |
|
|
| Eedis wrote: | | ...There is no harm in that. |
Fine in theory, but I have to agree with jarhed - you really should stop trying to rush through this and learn it properly, otherwise you'll end up wasting more time, and if you actually get it working, you won't even know why!
There is simply NO WAY you can write a program without having a proper knowledge of the language you're writing in.
If you're new to programming, I wouldn't recommend starting with AHK. It's very quirky in its syntax. |
|
| Back to top |
|
 |
Eedis
Joined: 12 Jun 2009 Posts: 1158 Location: Indianapolis IN, USA
|
Posted: Fri Jan 15, 2010 7:03 pm Post subject: |
|
|
I'm not new to this or other programming languages. I wasn't wasting any time by fiddling with it and I do learn it. So you can stop thinking that I don't because you don't know what I do in my spare time or how I learn things and prefer to learn things. On the other hand, at least I attempted and actually looked into the help document and read as much as I could for a good hour or so before posting.
On the other hand... I got it to work and I do know why. So thanks for any help you guys provided. _________________ www.AutoHotkey.net/~Eedis
I love my wife and daughter so much.
 |
|
| Back to top |
|
 |
BoffinbraiN
Joined: 16 Nov 2009 Posts: 114
|
Posted: Fri Jan 15, 2010 7:59 pm Post subject: |
|
|
| Aye... Well I just posted in another thread about how horrible and 'freestyle' AHK's syntax is, so I sympathise. |
|
| Back to top |
|
 |
Zaelia
Joined: 31 Oct 2008 Posts: 604 Location: France
|
Posted: Fri Jan 15, 2010 8:19 pm Post subject: |
|
|
And you know what a programming language to start? I personally look for python but I fear for its future ... Without AHK I think I'll never managed to wait for results in programming as quickly, even if this is the script ...
ahk does not bother to compile, to have a super editor or IDE, to write too much online for a result, memory management, and ultimately to a noob who does not bored is not worse. ..
However ahk seems to be good for a noob noob who wants to stay but not for a noob who's going to become a professional programmer...
at the end, they are a lot of help in this forum! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|