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

Username:   Password: 
 RegisterRegister   
 Reference through nil pointer?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
facultyofmusic




PostPosted: Mon Dec 22, 2008 12:56 pm   Post subject: Reference through nil pointer?

I'm doing my ISP and i have this piano keyboard I have to make work. This part of the program is for the black piano buttons:
Turing:

import GUI

var mainScreen : int := Window.Open ("position:65;50,graphics:900;600")
var picID : int
var blackKeyPlayButton : string

%The Display Procedure
%BLACK KEY RESPONSES
proc playBlackResponse
    play (blackKeyPlayButton)
end playBlackResponse

proc display
    %The black keys
    drawfillbox (127, 420, 157, 550, 7)
    picID := Pic.New (127, 420, 152, 550)

    var black_key_button1 : int := GUI.CreatePictureButton (127, 420, picID, playBlackResponse)
    var black_key_button2 : int := GUI.CreatePictureButton (172, 420, picID, playBlackResponse)
    var black_key_button3 : int := GUI.CreatePictureButton (255, 420, picID, playBlackResponse)
    var black_key_button4 : int := GUI.CreatePictureButton (300, 420, picID, playBlackResponse)
    var black_key_button5 : int := GUI.CreatePictureButton (343, 420, picID, playBlackResponse)

    loop
        if GUI.GetEventWidgetID = black_key_button1 then
            blackKeyPlayButton := "c+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "d+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "f+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "g+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "a+"
        end if
        exit when GUI.ProcessEvent
    end loop

end display

display


The problem is that when I run it, it Widget thingy pops up and shows me a error. Which says "reference through nil pointer". What does this mean? What part of the program is wrong? Thanks for your help


Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
octopi




PostPosted: Mon Dec 22, 2008 3:01 pm   Post subject: Re: Reference through nil pointer?

If you try to access an object which hasn't been created yet, then you'll get this error. I'm not too familiar with Turing, and I can't find the error in your code, does the program point to a certain line as the cause of the problem?

Can you access a procedure without putting ()'s on the end of it?
playBlackResponse()

Also...

Turing:

        if GUI.GetEventWidgetID = black_key_button1 then
            blackKeyPlayButton := "c+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "d+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "f+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "g+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "a+"
        end if


should be: shouldn't it?
Turing:

        if GUI.GetEventWidgetID = black_key_button1 then
            blackKeyPlayButton := "c+"
        elsif GUI.GetEventWidgetID = black_key_button2 then
            blackKeyPlayButton := "d+"
        elsif GUI.GetEventWidgetID = black_key_button3 then
            blackKeyPlayButton := "f+"
        elsif GUI.GetEventWidgetID = black_key_button4 then
            blackKeyPlayButton := "g+"
        elsif GUI.GetEventWidgetID = black_key_button5 then
            blackKeyPlayButton := "a+"
        end if


Sorry I can't be more help, I really don't know Turing, perhaps another user can help you out more.

btw: those syntax tags are pretty touchy...
Clayton




PostPosted: Mon Dec 22, 2008 3:36 pm   Post subject: RE:Reference through nil pointer?

Think of it this way, if no event has happened yet, then how could GetEventWidgetID possibly have any sort of value? You need to include that in your action procedure from the button.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: