 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
dakun Guest
|
Posted: Fri Jul 04, 2008 3:10 am Post subject: help, dice program not counting dice? |
|
|
hello, im kinda new to the gui and variable aspect of ahk, but ive had prior programming experiance. ive ran into an issue that doesnt make sense.
when it rolls the dice, it doesnt count how many of a number shows up. in fact it doesnt even seem to be true in the if statement when it supposed to be.
the programs half finished but the problem should still be apperant
it accures at
| Code: | ;checks for 20s
if (20==%rand%)
20s+=1 |
| Code: | Gui, Add, Edit, x246 y77 w200 h300 voutput ,
Gui, Add, Text, x126 y7 w230 h30 , Pick what you want to roll
;buttons
Gui, Add, Button, x26 y77 w80 h30 gd20, d20
Gui, Add, Button, x26 y127 w80 h30 gd12 , d12
Gui, Add, Button, x26 y177 w80 h30 , d10
Gui, Add, Button, x26 y227 w80 h30 , d8
Gui, Add, Button, x26 y327 w80 h30 , d4/d2
Gui, Add, Button, x26 y277 w80 h30 , d6/d3
;combo boxes
Gui, Add, ComboBox, x126 y77 w100 h20 vd20box r10, 1||2|3|4|5|6|7|8|9|10
Gui, Add, ComboBox, x126 y127 w100 h21 vd12box r10 , 1||2|3|4|5|6|7|8|9|10
; Generated using SmartGUI Creator 4.0
Gui, Show, x17 y326 h409 w479, Dice roller
Return
d20:
20s:=0
it=1
GuiControl,, output,
gui,submit,noHide
loop %d20box%{
Random,rand,1,20
GuiControl,, output,%output% %rand%,
gui,submit,noHide
%it%++
;checks for 20s
if (20==%rand%)
20s+=1
}
GuiControl,, output, 20s:%20s%`n`n %output%
return
d12:
Random, rand,1,12
GuiControl,, output, %output% %rand%
gui,submit,noHide
return
GuiClose:
ExitApp |
|
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1071
|
Posted: Fri Jul 04, 2008 5:30 am Post subject: |
|
|
if (20 = rand) _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
dakun Guest
|
Posted: Fri Jul 04, 2008 8:25 pm Post subject: |
|
|
| [VxE] wrote: | | if (20 = rand) |
whats the difference between %rand% and rand? |
|
| Back to top |
|
 |
Red Hat Boy
Joined: 10 Apr 2008 Posts: 110
|
Posted: Fri Jul 04, 2008 8:54 pm Post subject: |
|
|
| Code: | ; (Bubbles1)a string, or a variable where noted
; (%Bubbles1%)retrieving the contents of a variable, where a variable isn't expected
Bubbles1 = a little soap
Bubbles2 = more soap
Num = 2
; (=)var equals value
; (:=)var equals expression
nice = doggy
HowManyBubbles := Bubbles%Num%
Msgbox Bubbles1 ; this outputs (Bubbles1).
Msgbox %Bubbles1% ; this outputs the contents of Bubbles1, (a little soap).
Msgbox %nice%, %HowManyBubbles% now! ; this outputs the contents of HowManyBubbles, (doggy, more soap now!). |
Useful? No.
Informative? Maybe.
Edit: Okay, the (:=) wasn't even necessary in my example. Sorry. _________________ I slit the sheet, the sheet I slit,
and on the slitted sheet I sit. ;~} |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1071
|
Posted: Sat Jul 05, 2008 3:08 am Post subject: |
|
|
| dakun wrote: | | whats the difference between %rand% and rand? |
| Code: | rand = mary
mary = bob
If rand = mary
msgbox % mary " loves " %rand% | clearer? _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
Wicked
Joined: 07 Jun 2008 Posts: 29
|
Posted: Sat Jul 05, 2008 10:07 am Post subject: |
|
|
You can't have %Var% inside if the brackets of an If statement.
Ahk automatically looks at what's typed in a bracketed if statement as a variable. That's why you would have to do things like this:
String = False
| Code: | If (String == "False")
{
MsgBox, Pwn!
} |
Leaving it as:
| Code: | | If (String == False) |
Would really mean if the variable 'String' is equal to the variable 'False' then... You get the point.
Since, as said above, Ahk already sees them as variables, there is no need for:
|
|
| Back to top |
|
 |
dakun Guest
|
Posted: Sun Jul 06, 2008 9:42 pm Post subject: |
|
|
| Wicked wrote: | You can't have %Var% inside if the brackets of an If statement.
Ahk automatically looks at what's typed in a bracketed if statement as a variable. That's why you would have to do things like this:
String = False
| Code: | If (String == "False")
{
MsgBox, Pwn!
} |
Leaving it as:
| Code: | | If (String == False) |
Would really mean if the variable 'String' is equal to the variable 'False' then... You get the point.
Since, as said above, Ahk already sees them as variables, there is no need for:
|
thanks, ill have to keep this in mind |
|
| 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
|