Whack-a-mole process/button gone awry.
Author |
Message |
TheGreatSanguini
|
Posted: Fri Jan 18, 2008 1:37 pm Post subject: Whack-a-mole process/button gone awry. |
|
|
I'm constantly recieving the "Expression is not a variable" error from turing when I try to run the following program. I'm not sure where the problem is, but one thing is for sure - I can't find it myself. I will bold the process that turing does.
I'm working in turing 4.0.3
code: |
%Import the GUI library
import GUI
%Declare Global Variables
var mousex, mousey, mouseb, mole, background, molebutton, scorecounter : int
var holex : array 1 .. 3 of int := init (100, 300, 500)
var holey : array 1 .. 2 of int := init (125, 275)
scorecounter := 0
%Creating the pictures for use in the program
Draw.FillOval (50, 50, 50, 50, brightred)
mole := Pic.New (0, 0, 100, 100)
GUI.SetBackgroundColour (yellow)
Draw.FillOval (100, 125, 50, 50, black)
Draw.FillOval (100, 275, 50, 50, black)
Draw.FillOval (500, 125, 50, 50, black)
Draw.FillOval (500, 275, 50, 50, black)
Draw.FillOval (300, 125, 50, 50, black)
Draw.FillOval (300, 275, 50, 50, black)
background := Pic.New (0, 0, maxx, maxy)
%Declare processes
process procMolehit
GUI.Dispose (molebutton)
scorecounter := scorecounter + 1
end procMolehit
%Setting the screen
View.Set ("graphics:600;400,nobuttonbar,offscreenonly,title:Whack-a-Mole,position:100;100")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN PROGRAM %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i : 1 .. 40
molebutton := GUI.CreatePictureButton (holex (Rand.Int (1, 3)), holey (Rand.Int (1, 2)), mole, [b]procMolehit[/b])
Pic.Draw (background, 0, 0, picUnderMerge)
View.Update
Time.Delay (100)
GUI.Dispose (molebutton)
end for
%Keeping GUI alive throughout the program
loop
exit when GUI.ProcessEvent
end loop
|
Any help would be appreciated, even if it's not directly related to fixing the problem - I'm sure my program could be simplified or improved in SOME other way as well. Every little bit counts.
Thanks in advance. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
HeavenAgain
|
Posted: Fri Jan 18, 2008 2:23 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
shouldn't it be procedure instead of process? |
|
|
|
|
|
TheGreatSanguini
|
Posted: Sat Jan 19, 2008 7:45 pm Post subject: Re: Whack-a-mole process/button gone awry. |
|
|
... excuse me for five minutes while I bash my head against a brick wall.
Thanks for pointing that out. Can't believe I spent four hours tweaking and agonizing over THAT.
The current incarnation of the program now looks as follows, but I've run into another snag - the buttons don't actually DO anything for some reason, and the score refuses to display.
I'm not sure why I'm having either of those problems. I really appreciate any help on this matter.
code: |
%Import the GUI library
import GUI
%Declare Global Variables
var mousex, mousey, mouseb, mole, background, molebutton, scorecounter : int
var score : real := 0
var holex : array 1 .. 3 of int := init (50, 250, 450)
var holey : array 1 .. 2 of int := init (75, 225)
var fontscore : int := Font.New("Arial:25x20")
%Creating the pictures for use in the program
Draw.FillOval (50, 50, 50, 50, brightred)
mole := Pic.New (0, 0, 100, 100)
GUI.SetBackgroundColour (yellow)
Draw.FillOval (100, 125, 50, 50, black)
Draw.FillOval (100, 275, 50, 50, black)
Draw.FillOval (500, 125, 50, 50, black)
Draw.FillOval (500, 275, 50, 50, black)
Draw.FillOval (300, 125, 50, 50, black)
Draw.FillOval (300, 275, 50, 50, black)
background := Pic.New (0, 0, maxx, maxy)
%Declare processes
procedure procMolehit
score := score + 1
GUI.Dispose (molebutton)
end procMolehit
%Setting the screen
View.Set ("graphics:600;400,nobuttonbar,offscreenonly,title:Whack-a-Mole,position:100;100")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN PROGRAM %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i : 1 .. 40
molebutton := GUI.CreatePictureButton (holex (Rand.Int (1, 3)), holey (Rand.Int (1, 2)), mole, procMolehit)
Pic.Draw (background, 0, 0, picUnderMerge)
scorecounter:= GUI.CreateLabelFull(500,300,realstr(score,10),100,100,GUI.LEFT+GUI.BOTTOM,fontscore)
View.Update
Time.Delay (1000)
GUI.Dispose (molebutton)
GUI.Dispose (scorecounter)
cls
end for
%Keeping GUI alive throughout the program
loop
exit when GUI.ProcessEvent
end loop
|
Thanks again,
-Sanguini |
|
|
|
|
|
TheGreatSanguini
|
Posted: Mon Jan 21, 2008 12:16 pm Post subject: Re: Whack-a-mole process/button gone awry. |
|
|
Why doesn't the button do anything?!
I've tried everything I know. The button just still won't do anything. I've gotten the label of score to display, but that's irrelevant without the button working to increase it. I've put other things into the button's process, like put commands etc, but nothing shows up. I have no idea where this problem would be located, and turing doesn't even give me an error message. I really need some help on this one, I'm in over my head.
-Sanguini |
|
|
|
|
|
HeavenAgain
|
Posted: Mon Jan 21, 2008 12:50 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
noticed your code: | loop
exit when GUI.ProcessEvent
end loop | is after the for loop, which means, after looping for 40 times, then you go into this checking or whatever it is, so no matter how hard you click on the button, nothing will happen untill you reached here |
|
|
|
|
|
TheGreatSanguini
|
Posted: Mon Jan 21, 2008 10:35 pm Post subject: Re: Whack-a-mole process/button gone awry. |
|
|
So does that mean that I have to make my main program a forked procedure or something in order to have it running at the same time as the GUI loop? |
|
|
|
|
|
Clayton
|
Posted: Mon Jan 21, 2008 10:36 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
Incorporate that loop in your other loop. |
|
|
|
|
|
TheGreatSanguini
|
Posted: Mon Jan 21, 2008 10:55 pm Post subject: Re: Whack-a-mole process/button gone awry. |
|
|
When I simply incorporate the GUI.ProcessEvent Loop into my main loop, the button still refuses to work. If you could explain further how to properly do it (in case there's more to it then simply copying and pasting it into the other) I'd be all ears. However, with my main program as a forked process, the button works, the counter goes up, and everything's working. I replaced the GUI.Dispose in the button process with GUI.Disable and then drew over the disabled button. Everything's working, everything's good, and I'm happy.
Thanks for all of your help, and many bits to you, good sir!
EDIT: Gah, I spoke too soon and jinxed myself it seems. While the first few tests through the program yielded no errors, I now keep getting "Segmentation violation". Again, something that might as well be equal parts magic and czechoslovakian to my eyes. What is segmentation violation? If you could explain to me what is happening in my program to cause it, again you would have my gratitude. But if not, I'd like to at least know what it is I'm dealing with.
code: |
%Import the GUI library
import GUI
%Declare Variables
var mousex, mousey, mouseb, mole, background, molebutton, scorecounter : int
var holex : array 1..3 of int := init(50,250,450)
var holey : array 1..2 of int := init(75,225)
var scorefont : int := Font.New('Technical:25x22')
var score : real
score := 0
%Creating the pictures for use in the program
Pic.ScreenLoad('MontyMole.bmp',0,0,picCopy)
mole := Pic.New(0,0,100,100)
GUI.SetBackgroundColour(yellow)
Draw.FillOval(100,125,50,50,black)
Draw.FillOval(100,275,50,50,black)
Draw.FillOval(500,125,50,50,black)
Draw.FillOval(500,275,50,50,black)
Draw.FillOval(300,125,50,50,black)
Draw.FillOval(300,275,50,50,black)
background := Pic.New(0,0,maxx,maxy)
%Setting the screen
View.Set('graphics:600;400,nobuttonbar,offscreenonly,title:Whack-a-Mole,position:100;100')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PROCEDURES %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Declare processes
procedure procMolehit
score := score+1
GUI.Disable(molebutton)
Pic.Draw(background,0,0,picCopy)
scorecounter := GUI.CreateLabelFull(300,350,realstr(score,10),0,0,GUI.LEFT+GUI.BOTTOM,scorefont)
View.Update
end procMolehit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN PROGRAM %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process Mainprogram
for i : 1..40
molebutton := GUI.CreatePictureButtonFull(holex(Rand.Int(1,3)),holey(Rand.Int(1,2)), mole, procMolehit,100,100,'^A',false)
Pic.Draw(background,0,0,picUnderMerge)
scorecounter := GUI.CreateLabelFull(300,350,realstr(score,10),0,0,GUI.LEFT+GUI.BOTTOM,scorefont)
View.Update
Time.Delay(500)
GUI.Dispose(molebutton)
GUI.Dispose(scorecounter)
cls
end for
end Mainprogram
fork Mainprogram
%Keeping GUI alive throughout the program
loop
exit when GUI.ProcessEvent
end loop
|
I've fiddled around with the various settings of the program, and it seems as though it's linked somehow to the time delay, though I'm not sure the nature of the relationship. When Time.Delay is 750, I get segmentation violation less often. Still, this bug needs to be ironed out for my progam to be complete.
Thanks in advance, and thanks for previous.
-Sanguini
[/code] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGreatSanguini
|
Posted: Tue Jan 22, 2008 4:58 pm Post subject: Re: Whack-a-mole process/button gone awry. |
|
|
Another problem, now that I added more to the program, for some reason I'm getting the error "Color value of -572662307 is out of bounds."
Is there at least some sort of error library where I can look up random crap like this? I want to be able to solve some of my problems on my own, for when you guys aren't willing to help me. Still, since I'm in a bind I'd like any help I can get.
What's wrong with this stuff?
code: |
%Import the GUI library
import GUI
%Declare Variables
var mousex, mousey, mouseb, mole, background, molebutton, scorecounter, namegetter, title : int
var holex : array 1..3 of int := init(50,250,450)
var holey : array 1..2 of int := init(75,225)
var scorefont : int := Font.New('Technical:25x22')
var titlefont : int := Font.New('BankGothic Md BT:35x25')
var score : real
var name : string
score := 0
%Creating the pictures for use in the program
Pic.ScreenLoad('MontyMole.bmp',0,0,picCopy)
mole := Pic.New(0,0,100,100)
GUI.SetBackgroundColour(yellow)
Draw.FillOval(100,125,50,50,black)
Draw.FillOval(100,275,50,50,black)
Draw.FillOval(500,125,50,50,black)
Draw.FillOval(500,275,50,50,black)
Draw.FillOval(300,125,50,50,black)
Draw.FillOval(300,275,50,50,black)
background := Pic.New(0,0,maxx,maxy)
%Setting the screen
View.Set('graphics:600;400,nobuttonbar,offscreenonly,title:Whack-a-Mole,position:100;100')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PROCEDURES %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure procMolehit
score := score+1
Pic.Draw(background,0,0,picCopy)
scorecounter := GUI.CreateLabelFull(300,350,realstr(score,10),0,0,GUI.LEFT+GUI.BOTTOM,scorefont)
for decreasing j : 2900..900 by 1000
Music.Sound(j,50)
end for
GUI.Disable(molebutton)
View.Update
end procMolehit
procedure procNamethingy(name : string)
end procNamethingy
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN PROGRAM %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process Gmusic
loop
Music.PlayFile("playfile.mp3")
end loop
end Gmusic
fork Gmusic
% Title Screen
cls
GUI.SetBackgroundColour(yellow)
Text.Colour(red)
Text.ColourBack(yellow)
Text.Locate(24,50)
put "By: Michael S. Emmons"
Text.Locate(10,20)
put "What is your name?: "..
title := GUI.CreateLabelFull(100,300,"Whack-a-Mole",0,0,GUI.LEFT+GUI.BOTTOM,titlefont)
View.Update
get name
namegetter := GUI.CreateTextField(150,200,200," ",procNamethingy)
cls
for k : 1..255
Text.Colour(k)
put "Prepare yourself! "..
View.Update
end for
cls
process Mainprogram
for i : 1..20
Pic.Draw(background,0,0,picCopy)
molebutton := GUI.CreatePictureButtonFull(holex(Rand.Int(1,3)),holey(Rand.Int(1,2)), mole, procMolehit,100,100,'^A',false)
scorecounter := GUI.CreateLabelFull(300,350,realstr(score,10),0,0,GUI.LEFT+GUI.BOTTOM,scorefont)
View.Update
Time.Delay(750)
GUI.Dispose(molebutton)
GUI.Dispose(scorecounter)
cls
end for
put "Congratulations, ",name,"!"
View.Update
for u : 1..50
Draw.FillStar(20,20,u,u,green)
View.Update
Draw.FillBox(20,20,70,70,yellow)
end for
end Mainprogram
fork Mainprogram
loop
exit when GUI.ProcessEvent
end loop
|
|
|
|
|
|
|
HeavenAgain
|
Posted: Tue Jan 22, 2008 5:35 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
uh i think the error is like this, you created a button called molebutton and when you click on it, it calls to the procedure, and it disable itself... thats kind of odd, and after a bit you dispose it, while it is already disabled.... weird!
so i changed it to something like this,
code: | procedure procMolehit
score := score + 1
%%% no more disable
Pic.Draw (background, 0, 0, picCopy)
scorecounter := GUI.CreateLabelFull (300, 350, realstr (score, 10), 0, 0, GUI.LEFT + GUI.BOTTOM, scorefont)
View.Update
end procMolehit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN PROGRAM %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process Mainprogram
for i : 1 .. 40
molebutton := GUI.CreatePictureButtonFull (holex (Rand.Int (1, 3)), holey (Rand.Int (1, 2)), mole, procMolehit, 100, 100, '^A', false)
Pic.Draw (background, 0, 0, picUnderMerge)
scorecounter := GUI.CreateLabelFull (300, 350, realstr (score, 10), 0, 0, GUI.LEFT + GUI.BOTTOM, scorefont)
View.Update
Time.Delay (500)
GUI.Disable (molebutton) %%put disable here
GUI.Dispose (scorecounter) %% not so sure about this one
cls
end for
end Mainprogram
fork Mainprogram | and about the color like whatever the error said, you are trying to put a value thats invalid in something like colour(your_huge_ass_number) and it got out of bounded, im thinking you might have misplaced a font inside a colour? or something like that, try and see if you can catch that little bugger best of luck! |
|
|
|
|
|
ericfourfour
|
Posted: Tue Jan 22, 2008 6:07 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
You should not be using processes for this. Pretty much everything you do in Turing does not need to be multithreaded.
The purpose of multithreading is to divide the cpu load onto more than one processor. Mostly all programs made in Turing do not need the power or complexity of working with multiple threads.
Anyway, if you find yourself using processes in Turing, you are probably adding a lot of unnecessary work. A combination of the GUI and processes is a signal for this. |
|
|
|
|
|
TheGreatSanguini
|
Posted: Tue Jan 22, 2008 6:24 pm Post subject: Re: Whack-a-mole process/button gone awry. |
|
|
Thanks yet again, HeavenAgain. Yes, turns out that the disposing after it was already disabled was causing the segmentation error.
However, for some reason, it was the background music that was causing the color error.... Which is completley bizarre to me naturally.
I've gone through the entire program, made sure each individual portion of it works on its own, and together. Now everything except the background music is working, and I think I'll just ignore that.
Thanks a million, more bits to you for your outstanding help. I'll make sure to continue revising and add more comments when I reach a stumbling block.
-Sanguini |
|
|
|
|
|
HeavenAgain
|
Posted: Tue Jan 22, 2008 6:32 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
you should say, "oh thank Heavens Again " anyways, see that is your problem with the music, you can try something like
code: | Music.PlayFileLoop ("playfile.mp3") |
at the beginning of the code, so it will keep on playing that song, and looping by itself. and add at the end of your program, so then it will call it to stop playing the music when your program is done, there is an example in the turing help section, just search for "music" as keyword, and ta da |
|
|
|
|
|
Clayton
|
Posted: Tue Jan 22, 2008 6:39 pm Post subject: RE:Whack-a-mole process/button gone awry. |
|
|
And if not Music.PlayFileLoop() you can also check out Music.PlayFileReturn() as they both eliminate the need for processes. PlayFileReturn plays the selection once, while PlayFileLoop does as it implies, it just loops the music over and over again. |
|
|
|
|
|
|
|