 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
conchfeld
Joined: 21 Sep 2008 Posts: 16
|
Posted: Tue Sep 01, 2009 6:04 am Post subject: checking if somethings an integer isn't working well for me. |
|
|
ok so heres my script.
| Code: | tempo := 120 ;default tempo
newValue := 4 ;default new value
newTempo := 120 ;default new tempo
; Gui, sub-command [, Param2, Param3, Param4]
Gui, Add, Text, x95 y15, Base Tempo:
Gui, Add, Edit, x165 y13 vtempo, 120
Gui, Add, Text, x88 y40, New Beat Value:
Gui, Add, Edit, x172 y36 vnewValue w25, 4
Gui, show, W300 H100, Rhythmic Modulation Assistant
gui, add, button, x95 y60 gupdateValues, What's my tempo?
^!r::
reload
return
updateValues:
gui, submit, nohide
nameNewValue(newValue)
newTempo := (60 / ( ( (60 / tempo)*4) / newValue ) )
msgbox Giving the %newValueName% the beat, our new tempo should be %newTempo% bpm.
return
!^y::
test := 3 / 3
msgbox %test%
return
isDivisible(value, divisor)
{
msgbox is %value% divided by %divisor% an integer?
if (value / divisor) is integer
{
msgBox yes, %value% is evenly divisible by %divisor%.
return, true
}
else if (value / divisor) is not integer {
msgBox no, %value% is not evenly divisible by %divisor%.
return, false
}
}
nameNewValue(newValue) {
if (isDivisible(newValue, 3) = true)
rhythType := "triplet"
if (isDivisible(newValue, 4))
rhythType := ""
if (isDivisible(newValue, 5) = true)
rhythType := "quintuplet"
if (isDivisible(newValue, 7) = true)
rhythType := "septuplet"
else
rhythType := "tuplet"
global newValueName := rhythType
} |
particular trouble spot is my isdivisible function.
| Code: | isDivisible(value, divisor)
{
msgbox is %value% divided by %divisor% an integer?
if (value / divisor) is integer
{
msgBox yes, %value% is evenly divisible by %divisor%.
return, true
}
else if (value / divisor) is not integer {
msgBox no, %value% is not evenly divisible by %divisor%.
return, false
}
} |
Why is it returning true all the time? What am I doing wrong? _________________ Composer
http://www.joshuaevensen.com |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Tue Sep 01, 2009 6:24 am Post subject: |
|
|
| Documentation wrote: | if var is type
if var is not type |
Example: | Code: | var := value / divisor
if var is integer ; -or- if !mod(value, divisor)
...
else
... |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Last edited by jethrow on Tue Sep 01, 2009 6:45 am; edited 1 time in total |
|
| Back to top |
|
 |
conchfeld
Joined: 21 Sep 2008 Posts: 16
|
Posted: Tue Sep 01, 2009 6:35 am Post subject: |
|
|
so...
| Code: | isDivisible(value, divisor)
{
msgbox is %value% divided by %divisor% an integer?
var := value / divisor
if var is integer
msgBox yes, %value% is evenly divisible by %divisor%.
else
msgBox no, %value% is not evenly divisible by %divisor%.
} |
?
If that's right, it still isn't working. _________________ Composer
http://www.joshuaevensen.com |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Tue Sep 01, 2009 6:56 am Post subject: |
|
|
Yeah, you're right . I think the issue is with the number format after dividing (see SetFormat). I'd just use: | Code: | | if !mod(value, divisor) ; it's divisible |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Tue Sep 01, 2009 1:04 pm Post subject: |
|
|
| AHK Help File wrote: | | True divide (/): Unlike EnvDiv, true division yields a floating point result even when both inputs are integers. For example, 3/2 yields 1.5 rather than 1, and 4/2 yields 2.0 rather than 2. |
|
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Tue Sep 01, 2009 2:23 pm Post subject: |
|
|
| Code: | If !mod( mod(value,divisor) , 1 )
Msgbox integer! |
OR
| Code: | Result := mod( value , divisor ) + 0
If Result is integer
Msgbox integer! |
_________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
conchfeld
Joined: 21 Sep 2008 Posts: 16
|
|
| Back to top |
|
 |
BoBo³ Guest
|
Posted: Tue Sep 01, 2009 4:43 pm Post subject: |
|
|
@joshua alias conchfeld
Interesting music! Same parts reminds me a little at David Sylvian
*switch topic*
Would you mind to provide code instead of an compiled exe? Just in case you're interested to get bancrupt for the reason of millions of downloads of your app  |
|
| Back to top |
|
 |
conchfeld
Joined: 21 Sep 2008 Posts: 16
|
Posted: Tue Sep 01, 2009 5:23 pm Post subject: |
|
|
Its too niche to get millions of downloads haha, but I will post code. Here.
| Code: | tempo := 120 ;default tempo
newValue := 4 ;default new value
newTempo := 120 ;default new tempo
; Gui, sub-command [, Param2, Param3, Param4]
Gui, Add, Text, x95 y15, Base Tempo:
Gui, Add, Edit, x165 y13 vtempo, 120
Gui, Add, Text, x88 y40, New Beat Value:
Gui, Add, Edit, x172 y36 vnewValue w25, 4
Gui, show, W300 H120, Rhythmic Modulation Assistant
gui, add, button, x95 y60 gupdateValues, What's my tempo?
Gui, Add, Text, x2 y90, (NOTE: if you get too ridiculous, the note types will be wrong.)
^!r::
reload
return
updateValues:
gui, submit, nohide
nameNewValue(newValue)
newTempo := (60 / ( ( (60 / tempo)*4) / newValue ) )
msgbox If our new beat is a %newValueName%, our new tempo should be %newTempo% bpm.
return
!^y::
test := 3 / 3
msgbox %test%
return
isDivisible(value, divisor)
{
;msgbox is %value% divided by %divisor% an integer?
if !mod(value, divisor)
return true
else
return false
}
nameNewValue(newValue) {
if (isDivisible(newValue, 3) = true)
rhythType := "triplet"
else if (isDivisible(newValue, 4))
rhythType := ""
else if (isDivisible(newValue, 5) = true)
rhythType := "quintuplet"
else if (isDivisible(newValue, 7) = true)
rhythType := "septuplet"
else
rhythType := newValue . "tuplet"
if newValue between 0 and 3
rhythClass := "half note "
else if newValue between 4 and 7
rhythClass := "quarter note "
else if newValue between 9 and 15
rhythClass := "eighth note "
else if newValue between 16 and 31
rhythClass := "sixteenth note "
else if newValue between 32 and 63
rhythClass := "thirty second note "
global newValueName := rhythClass . rhythType
} |
Glad you dig the music, man. Cool. _________________ Composer
http://www.joshuaevensen.com |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Tue Sep 01, 2009 5:38 pm Post subject: |
|
|
Just some thoughts: | Code: | isDivisible(value, divisor) {
Return mod(value, divisor) ? false : true
} |
| Code: | | rhythType := !mod(newValue, 3) ? "triplet" : (!mod(newValue, 4) ? "" : (!mod(newValue, 5) ? "quintuplet" : (!mod(newValue, 7) ? "septuplet" : newValue . "tuplet"))) |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Tue Sep 01, 2009 5:55 pm Post subject: |
|
|
I was just about to say for that function you only need to specify one possible result; the script will assume the other result if the defined is not true:
| Code: | isDivisible(value, divisor) {
if !Mod(value, divisor)
return true
} |
But to that end, creating a function to perform the same action as an already existing function is kind of redundant, no?
| Code: | nameNewValue(newValue) {
if !Mod(newValue,3)
rhythType := "triplet"
else if !Mod(newValue,4)
rhythType := ""
else if !Mod(newValue,5)
rhythType := "quintuplet"
else if !Mod(newValue,7)
rhythType := "septuplet"
else
rhythType := newValue "tuplet"
if newValue between 0 and 3
rhythClass := "half note "
else if newValue between 4 and 7
rhythClass := "quarter note "
else if newValue between 9 and 15
rhythClass := "eighth note "
else if newValue between 16 and 31
rhythClass := "sixteenth note "
else if newValue between 32 and 63
rhythClass := "thirty second note "
return newValueName := rhythClass rhythType
} |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| 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
|