Assistance Needed - Button not working correctly for RPG style game.
Author |
Message |
Foxhunter
|
Posted: Tue Apr 27, 2010 9:41 am Post subject: Assistance Needed - Button not working correctly for RPG style game. |
|
|
What is it you are trying to achieve?
My friend and I are making a game for Gr. 10 Computer Science, and we decided to make an RPG kind of game. The objective is that you click a button to deal a random integer of damage to a monster, and when their 'Health' reaches >0 the screen is cleared or the actual monster is cleared, and you move on to the next monster unitl you hit the final boss.
What is the problem you are having?
The button on the code labeled 'Attack' doesn't work. The button itself is there, however when you click on it, nothing happens. It doesn't even register that you clicked.
Describe what you have tried to solve this problem
I've tried removing the picture, no results, and I really have no other clue what to do to solve the problem.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
CODE IS BELOW -
Turing: |
import GUI
setscreen("graphics:700;725")
var Saphiron := Pic.FileNew ("Saphiron.jpg")
var Health : int
var Damage : int
Health := 100
Damage := Rand.Int (10, 30)
procedure attack
locate (1, 1)
put "You have dealt ", Damage, " to Saphiron!"
Health := Health - Damage
end attack
var Attack : int := GUI.CreateButton (20, 10, 30, "Attack", attack )
loop
Pic.Draw (Saphiron, 150, 70, picMerge)
end loop
if Health >= 0 then
cls
end if
loop
exit when GUI.ProcessEvent
end loop
|
Please specify what version of Turing you are using
4.1.1
Thank you very much for any assistance you can lend!
~Foxhunter |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Tue Apr 27, 2010 10:46 am Post subject: Re: Assistance Needed - Button not working correctly for RPG style game. |
|
|
Foxhunter wrote:
That is an infinite loop. When a Turing program executes, each line is run in the order in which they appear in the file. This means any code appearing after an infinite loop will never be run. Since you put GUI.ProcessEvent in its own loop which comes after this infinite loop, it will never be run. Either put both inside of the same loop, or don't use an infinite loop. |
|
|
|
|
|
USEC_OFFICER
|
Posted: Tue Apr 27, 2010 11:37 am Post subject: RE:Assistance Needed - Button not working correctly for RPG style game. |
|
|
I don't even see the need for two loops. One mega loop should work just fine. |
|
|
|
|
|
chrisbrown
|
Posted: Tue Apr 27, 2010 11:39 am Post subject: RE:Assistance Needed - Button not working correctly for RPG style game. |
|
|
Also check your comparisons. You want Health <= 0. |
|
|
|
|
|
Foxhunter
|
Posted: Thu Apr 29, 2010 9:32 am Post subject: RE:Assistance Needed - Button not working correctly for RPG style game. |
|
|
God damn, now the if statement for when health = 0, doesn't seem to work. And when you click the button, it doesn't work more than once. After the first click it just stops and no longer works. |
|
|
|
|
|
TheGuardian001
|
Posted: Thu Apr 29, 2010 11:16 am Post subject: Re: Assistance Needed - Button not working correctly for RPG style game. |
|
|
I'd advise you to read this over one more time, then look at what you have written...
methodoxx wrote:
Also check your comparisons. You want Health <=0.
|
|
|
|
|
|
Foxhunter
|
Posted: Fri Apr 30, 2010 9:17 am Post subject: RE:Assistance Needed - Button not working correctly for RPG style game. |
|
|
I did read over it one time, and I did change the comparisons. IT still doesn't work.
That and the Rand.Int only assigns ONE number to damage, I want it to assign a different variable every single time they attack, and I've been struggling with that the past hour.
That and the "You have defeated Saphiron Message" comes up like fifty billion times, i've tried assigning a count to it and putting it in its own seperate loop. No luck.
Some assistance would be greatly appreciated. Here is the revamped code so far . .
import GUI
setscreen ("graphics:700;725")
var Saphiron := Pic.FileNew ("Saphiron.jpg")
var Health : int
var Damage : int
var count : int
Health := 100
Damage := Rand.Int (100, 300)
count := 0
process Playmusic
Music.PlayFile ("Doom 2 Shawn's got the shotgun.wav")
end Playmusic
fork Playmusic
procedure attack
locate (1, 1)
put "You have dealt ", Damage, " to Saphiron!"
delay (10)
Health := Health - Damage
end attack
Pic.Draw (Saphiron, 150, 70, picMerge)
loop
var Attack : int := GUI.CreateButton (20, 10, 30, "Attack", attack)
GUI.SetColor (Attack, brightred)
exit when GUI.ProcessEvent
end loop
loop
count := count + 1
if Health <= 0 then
put "You have defeated Saphiron!"
end if
exit when count = 1
end loop |
|
|
|
|
|
TheGuardian001
|
Posted: Fri Apr 30, 2010 12:29 pm Post subject: Re: Assistance Needed - Button not working correctly for RPG style game. |
|
|
You still have two seperate loops. This:
code: |
loop
var Attack : int := GUI.CreateButton (20, 10, 30, "Attack", attack)
GUI.SetColor (Attack, brightred)
exit when GUI.ProcessEvent
end loop
|
Is an infinite loop. GUI.ProcessEvent should never return true (Unless you call GUI.Quit, which kills the GUI), so this loop will never exit.
In addition, you shouldn't be creating a button inside of a loop. Take that line out and put it before the start of the loop.
Combine both of your loops into a single loop, and the program should work (slightly) better. However it will still have one problem:
code: |
exit when count = 1
|
That means this loop will only run once, meaning it isn't actually a loop. This condition should be removed entirely, since it isn't dependant on user input. This means it will exit after N repetitions, even if the user has never attacked.
Fix that, take the button declaration out of the loop, and combine both loops into one. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Foxhunter
|
Posted: Wed May 05, 2010 10:12 am Post subject: RE:Assistance Needed - Button not working correctly for RPG style game. |
|
|
Thank you! |
|
|
|
|
|
|
|