Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 piano keyboard help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
randomperson#5




PostPosted: Sun Jun 11, 2006 2:31 am   Post subject: piano keyboard help

hi...someone pleasee help me.... i'm desperate!! i'm making this piano keyboard program, it kind of works, but the program keeps crashing, and says "variable has no value".
code:

%Some random parts of my code
var notes : array 1 .. 53 of string
procedure processPlay
    for x : 1 .. totalInput
        play (notes (x)) %variable has no value
    end for
end processPlay

procedure userInput
        for i : 1 .. 53
        buttonwait ("down", rangex, rangey, button, buttonupdown)
        for x : 0 .. 120 by 30
            if rangex >= 0 + x and rangex <= 30 + x and rangey >= 470 and rangey <= 500 then
                if x = 0 then
                    notes (i) := "1"
                elsif x = 30 then
                    notes (i) := "2"........... (continues)

    if rangex >= 630 and rangex <= 665 and rangey >= 80 and rangey <= 100 then % play btn
            finished := true
        end if
        totalInput := i
        exit when finished
    end for
processPlay

end userInput


any help will be greatly appreciated!!
Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Sun Jun 11, 2006 7:00 am   Post subject: (No subject)

First of all, don't double post.

Second of all, read the [Turing FAQ] (Top of the help page)
Cervantes




PostPosted: Sun Jun 11, 2006 9:05 am   Post subject: (No subject)

I'm not seeing why that's causing a 'variable has no value' error just from the code you gave us.

Is it possible that you are calling 'processPlay' without having called 'userInput'? That would do it (unless you initialized totalInput to equal 0, which you should have).

This code can definately be cleaned up. You should look into parameters. Global variables are a bad way to go. Check out the Turing Walkthrough for a link to the tutorial on procedures and functions or check out the Turing Help file under 'prcoedure', 'function', and 'param...'

randomperson#5 wrote:

if x = 0 then
notes (i) := "1"
elsif x = 30 then
notes (i) := "2"........... (continues)

Do you see a pattern here? There's no need to have a giant if structure for this. Even if you did need to do it with conditionals like this, you'd use a case statement.

But we can still do better. Try this:
code:
notes (i) := ceil ((x + 1) / 30)

'ceil' is a function that rounds up to the nearest integer.
But that's not quite right, is it. That's assigned an integer to 'notes (i)'. We want to give it a string. Easy enough: we can type cast it, using 'intstr'.
code:
notes (i) := intstr (ceil ((x + 1) / 30))
Clayton




PostPosted: Sun Jun 11, 2006 11:18 am   Post subject: (No subject)

or if you dont understand where that came from you could use some kind of a nested for loop, also, i think that maybe one of your if conditions is wrong, so if one of them doesnt work (mainly the ones that give the variables values) then the variables dont get a value and your processPlay is called with no value to the variables Sad
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: