AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

trouble with variables containing another variable

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
conchfeld



Joined: 21 Sep 2008
Posts: 16

PostPosted: Sun Sep 21, 2008 5:39 am    Post subject: trouble with variables containing another variable Reply with quote

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
Back to top
View user's profile Send private message AIM Address
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun Sep 21, 2008 5:54 am    Post subject: Re: trouble with variables containing another variable Reply with quote

Solution: Replace all = with :=

conchfeld wrote:
Also, are variables case sensitive?


No! Not at all..

Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun Sep 21, 2008 6:05 am    Post subject: Reply with quote

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


Smile
Back to top
View user's profile Send private message Send e-mail
conchfeld



Joined: 21 Sep 2008
Posts: 16

PostPosted: Sun Sep 21, 2008 2:28 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message AIM Address
conchfeld



Joined: 21 Sep 2008
Posts: 16

PostPosted: Sun Sep 21, 2008 3:24 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message AIM Address
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Sun Sep 21, 2008 3:41 pm    Post subject: Reply with quote

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 Sun Sep 21, 2008 3:48 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Superfraggle



Joined: 02 Nov 2004
Posts: 1019
Location: London, UK

PostPosted: Sun Sep 21, 2008 3:43 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
conchfeld



Joined: 21 Sep 2008
Posts: 16

PostPosted: Sun Sep 21, 2008 4:25 pm    Post subject: Reply with quote

thanks guys, but again im new to all this so i dont quite know what those two suggestions mean.
_________________
Composer
http://www.joshuaevensen.com
Back to top
View user's profile Send private message AIM Address
conchfeld



Joined: 21 Sep 2008
Posts: 16

PostPosted: Tue Sep 23, 2008 4:31 am    Post subject: Reply with quote

Got it all figured out. Thanks.
_________________
Composer
http://www.joshuaevensen.com
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group