Computer Science Canada

Problems with GUI.Disable

Author:  Conagher [ Sun Dec 27, 2015 11:08 pm ]
Post subject:  Problems with GUI.Disable

What is it you are trying to achieve?
Hi i am having some problems clearing my GUI off the screen. Im trying clear them so they wont muck up my other GUI.

What is the problem you are having?
I am putting GUI.Disable (buttonX) and it tells me button X has not been declared. As far as i know i am creation buttons properly and this should not happen


Describe what you have tried to solve this problem
I have tried messing with the buttons and using GUI.hide instead of GUI.disable but none of my attempts worked.
Not really sure whats going on here.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is the Code i am having problems with. My goal is to have a working game however i cannot continue if this is not solved.
Hope you guys can help me out!

Turing:


import GUI
forward procedure gamesetup
forward proc gameinfo
forward proc titlescreen
forward proc startgame

%titlescreen
body titlescreen
cls
GUI.SetBackgroundColor (grey)
%main title Font
var intfont : int
intfont := Font.New ("Times New Roman:30")
Font.Draw ("Game Title", 250, 300, intfont, blue)

%buttons
var quitbtn:int:= GUI.CreateButton (150, 20, 400, "Quit", GUI.Quit)
var setupbtn:int:= GUI.CreateButton (150, 70, 100, "setup", gamesetup)
var infobtn:int:= GUI.CreateButton (150, 100, 100, "game information", gameinfo)
end titlescreen
titlescreen

%gameinfo screen
body gameinfo
GUI.Disable (quitbtn)
cls
var backtomenu : int := GUI.CreateButton (150, 0, 400, "back", titlescreen)
put "game info will be on this page"
end gameinfo


%gamesetup screen
body gamesetup
cls
GUI.SetBackgroundColor (grey)
Font.Draw ("game setup", 200, 300, defFontID, blue)
var startbtn : int := GUI.CreateButton (150, 70, 0, "start!", startgame)
end gamesetup


%startgame
body startgame
cls
end startgame

loop
    exit when GUI.ProcessEvent
end loop





Please specify what version of Turing you are using
I am using Turing 4.1.1

Author:  Jeffmagma [ Tue Dec 29, 2015 11:47 am ]
Post subject:  RE:Problems with GUI.Disable

Your button is not global, its a variable only inside titlescreen, so a GUI.Dispose outside titlescreen won't recognise it. Also, instead of body (procedureName), you could use body proc (procedureName). I think the only difference is that F2 still indents it

And why are you forwarding procedures?

Author:  Conagher [ Tue Dec 29, 2015 2:30 pm ]
Post subject:  RE:Problems with GUI.Disable

how do i make the variable global?

Author:  Insectoid [ Tue Dec 29, 2015 2:48 pm ]
Post subject:  RE:Problems with GUI.Disable

A variable declared inside a procedure, function, loop, etc. is called a 'local variable'. It cannot be used outside the block in which it is declared. A variable declared outside of any procedure or loop or whatever is called a global variable and it can be accessed anywhere in the code. Your button variables are declared inside procedures, which makes them local variables.


: