AutoHotkey Community

It is currently May 26th, 2012, 12:27 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: September 21st, 2008, 6:39 am 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
So I'm pretty new to scripting of any kind. I've done a bit, but this is my first major undertaking. I'm working on a script to do some cool music stuff w/the midi output library i found on this forum.

Anyway, the trouble is this in this snippet of code:

Code:
  Octave = 3 ; starting octave is 3 (middle C)
  Base = (Octave*12+set) ; our base note is our octave times 12-- so at start, from octave 3, it is 36-- middle C.
  TTon = 0 ; third tonality modifier. -1=minor, 0 = major, +1 = augmented
  STon = 0 ; seventh tonality modifier. -1 = dim, 0 = dominant, 1 = major
  FTon = 0 ; zero = normal, -1 = diminished
  Set = 0 ; 0 for set 1, 4 for set 2, 8 for set 3.
  ;here come the roots
  r1 = Base
  r2 = (r1+7)
  r3 = (r2+7)
  r4 = (r3+7)
  ;now the thirds
  t1 = (r1+4+Ton)
  t2 = (r2+4+Ton)
  t3 = (r3+4+Ton)
  t4 = (r4+4+Ton)
  ;fifths
  f1 = (r1+7+Fton)
  f2 = (r2+7+Fton)
  f3 = (r3+7+Fton)
  f4 = (r4+7+Fton)
  ;sevenths
  s1 = (r1+7+3+Ston)
  s2 = (r2+7+3+Ston)
  s3 = (r3+7+3+Ston)
  s4 = (r4+7+3+Ston)


When I set r1 to an actual number directly, like 36 (which is what it should equal by default, or at least thats what I want it to do), then the function later on in the script that is set up to use that variable works properly. However when I set R1 to equal Base, it no longer works, even though, as i understand it, the math I've put in should be giving it 36.

I'm thinking this might have something to do with the %variable% thing, dynamic variables or whatever they are? Not really sure, though. Again, total neophyte. I'll appreciate any input you guys have.

Also, are variables case sensitive?

Thanks a lot, all.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 21st, 2008, 6:54 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Solution: Replace all = with :=

conchfeld wrote:
Also, are variables case sensitive?


No! Not at all..

:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 7:05 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
There were a couple of logical errors, here it is fixed and tested:

Code:
#Persistent
  Ton := 0 ; <= You need to initialise this
  Set := 0 ; 0 for set 1, 4 for set 2, 8 for set 3. Relocated
  Octave := 3 ; starting octave is 3 (middle C)
  Base := (Octave*12+set) ; our base note is our octave times 12-- so at start, from octave 3, it is 36-- middle C.
  TTon := 0 ; third tonality modifier. -1=minor, 0 = major, +1 = augmented
  STon := 0 ; seventh tonality modifier. -1 = dim, 0 = dominant, 1 = major
  FTon := 0 ; zero = normal, -1 = diminished
Set := 0 ; 0 for set 1, 4 for set 2, 8 for set 3.
  ;here come the roots
  r1 := Base
  r2 := (r1+7)
  r3 := (r2+7)
  r4 := (r3+7)
  ;now the thirds
  t1 := (r1+4+Ton)
  t2 := (r2+4+Ton)
  t3 := (r3+4+Ton)
  t4 := (r4+4+Ton)
  ;fifths
  f1 := (r1+7+Fton)
  f2 := (r2+7+Fton)
  f3 := (r3+7+Fton)
  f4 := (r4+7+Fton)
  ;sevenths
  s1 := (r1+7+3+Ston)
  s2 := (r2+7+3+Ston)
  s3 := (r3+7+3+Ston)
  s4 := (r4+7+3+Ston)
Listvars 
Return


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 3:28 pm 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
Oh ok awesome I will try that out. What does initialize mean in this context?

Oh wait, I get it. Yeah, that was actually a mistake-- I renamed the variable to TTon but forgot to change it in the script.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 4:24 pm 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
Alright, so another problem now.

Code:
Velocity := 100

CheckVel:
   GetKeyState, Y, Joyy ; check left stick Y
   GetKeyState, X, Joyx ; check left stick X
   
         if Y > 55 ; if the left stick is down
            {
            Velocity:= -1(50 - Y * 2.54)
            }
         else if Y < 45 ; if the left stick is up
            {
            Velocity:= (50 - Y * 2.54)
            }
         return


So I am pretty sure I am not explaining the math to the computer the right way up there because A) it doesn't work and B) the variables its outputting don't match up with what it should be in my head.

Basically I want to generate a number from 1-127 based on how far Y is from 50 (so 100 would equal 127 and 1 would also equal approx 127). I figure I'd need basically one equation, Velocity:= (50 - Y * 2.54). Except when I go above 50, it becomes negative and I need the output positive-- no big deal, just do Velocity:= -1(50 - Y * 2.54) when Y goes above 50.

Anyway, so thats what I WANT to do and I think the math I've got works on paper, I am just not scripting it properly.

Go ahead though, lets hear it, show me how its done!

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 4:41 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Code:
#SingleInstance force
#NoEnv
SetFormat, Float, 0.2

Gui, Add, Text,,Y:
Gui, Add, Edit, x+5 Number
Gui, Add, UpDown, r0-100 vY
Gui, Add, Text, xm, Velocity:
Gui, Add, Edit, x+5 ReadOnly vV
Gui, Add, Button, Default, GO

Gui, Show
return
GuiClose:
ExitApp

ButtonGO:
Gui, Submit, NoHide
GuiControl,,V,% Abs((50-Y)*2.54)
return


Last edited by jaco0646 on September 21st, 2008, 4:48 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 4:43 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Something like this??

Code:
loop,100 {
    msgbox % a_index > 50 ? ((a_index - 50) * 2.54) : ((50 - a_index) * 2.54) 
}

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 5:25 pm 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
thanks guys, but again im new to all this so i dont quite know what those two suggestions mean.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2008, 5:31 am 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
Got it all figured out. Thanks.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: JamixZol, Morpheus, RUBn, SKAN, sks and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group