Help with my Virtual Pet Program
Author |
Message |
Graeme
|
Posted: Mon Apr 03, 2006 1:36 pm Post subject: Help with my Virtual Pet Program |
|
|
Okay, so i'm in the process of making a virtual pet game.
So far i have process which have the health being decreased and stamina etc.etc...
but I have the process's forked, and they run throughout the program at any given time.
and in those process's i have it so after it displayed the new health or stamina, the background is re-copied.
what i want to do is have it so..if i am say in a game within the virtual pet, i want it so the process will terminate until i go back to the main menu
any help would be awesome thanks |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Delos

|
Posted: Mon Apr 03, 2006 1:49 pm Post subject: (No subject) |
|
|
Simple answer: Don't use processes. They will make your life needlessly difficult, as you've already discovered. Instead, use the tried-test-and-true approach of procedures in a single loop:
pseudo: |
create pet
proc reduce_pet_life (byAmount : int)
pet.life -= byAmount
end
proc reduce_pet_stamina (byAmount : int)
pet.stamina -= byAmount
end
loop
if checking_time has passed
reduce_pet_life
reduce_pet_stamina
end
if main_menu requested
go to main_menu
end
end
|
Now, since you're in a central loop, you can control things appropriately and thus measure out how long it will be before the pet's attributes change. Also, since all input/output is controlled in one place, you can always exit that loop when needed and run other things. For instance, you could have your main loop as a nested loop, the outside loop housing the main menu...
pseudo: |
loop
main_menu
loop
if help_requested then
run_help
else if start_game_requested then
exit
end
end
% When out of main_menu selection loop, so start Main Loop
loop
if checking_time has passed
% ...
if main_menu requested then
exit
end
end
% When Main Loop exited, back into main_menu loop
end
|
Give that a spin and see how it goes. Check out the [Turing Tutorials] for info on Procedures and Functions. Make sure you're good with those before you attempt this. It will make your life a lot easier. |
|
|
|
|
 |
Graeme
|
Posted: Wed Apr 05, 2006 9:05 am Post subject: (No subject) |
|
|
Okay...well the reason I used processses was because my main menu is in a procedure, and you cant call another procedure inside a procedure...Here i will show you what I have..
------------------------------------------------------------------------------------
code: | process health_time
locate (14, 13)
put health
var health_decrease_time := 0
loop
if Time.Elapsed - health_decrease_time >= 60000 then
health_decrease_time := Time.Elapsed
health -= 25
locate (14, 13)
put health
Pic.ScreenLoad ("maintitle.bmp", 0, 0, picMerge)
end if
end loop
end health_time
process stamina_time
locate (12, 13)
put stamina
var stamina_decrease_time := 0
loop
if Time.Elapsed - stamina_decrease_time >= 30000 then
stamina_decrease_time := Time.Elapsed
stamina -= 10
locate (12, 13)
put stamina
Pic.ScreenLoad ("maintitle.bmp", 0, 0, picMerge)
end if
end loop
end stamina_time
body proc main
%MAIN MENU
cls
locate (10, 3)
put "Bank ", "$" % Displays Current Bank Balance
locate (10, 13)
put cash
locate (14, 3)
% put " Health ", health, "%"
put "Health ,"
locate (12,3)
put "Stamina: ", "%"%"
fork health_time
fork death
fork cash_bonus
fork cash_decrease
fork stamina_time
var button1 : int := GUI.CreateButton (200, 10, 0, "Buy Food", hello)
var button2 : int := GUI.CreateButton (200, 45, 0, "Go To Sleep", hi)
var button3 : int := GUI.CreateButton (200, 75, 0, "Play A Game", game)
var button4 : int := GUI.CreateButton (200, 105, 0, "SELF DESTRUCT MY PET", murder)
var button5 : int := GUI.CreateButton (200, 140, 0, "Play Guess A Number!", game2)
var button6 :int := GUI.CreateButton (200, 350, 0, "About Virtual Pet", about)
Pic.ScreenLoad ("maintitle.bmp", 0, 0, picXor)
end main
main |
Thanks again for your help |
|
|
|
|
 |
codemage

|
Posted: Wed Apr 05, 2006 10:39 am Post subject: (No subject) |
|
|
You can't define a procedure in another procedure.
You can most certainly call a procedure from another procedure though. |
|
|
|
|
 |
NikG
|
Posted: Wed Apr 05, 2006 11:27 am Post subject: (No subject) |
|
|
Please use the code /code tag when posting source code.
Also, next please post the entire source code... there were 12+ errors with what you posted.
Anyways, as codemage said, you can definitely CALL another proc from a proc. You'll have to modify your code though. The health_time and stamine_time procs should not have loops. You should only have one main body loop (the other procs could simply be to check the elapsed tiem and decrease health/stamina). |
|
|
|
|
 |
Graeme
|
Posted: Thu Apr 06, 2006 11:16 am Post subject: (No subject) |
|
|
Yeah thanks for the help, yeah i didn't post my full code, thats why their were so many errors, i can only posted the 2 process and one procedure...
thanks again |
|
|
|
|
 |
ZeroPaladn
|
Posted: Tue Apr 11, 2006 1:12 pm Post subject: (No subject) |
|
|
you could do what i do, just set a boolean (true or false) and an if statment at the beginning of each procedure, for example...
code: | var staminacheck : boolean := ture
proc decrease_stamina_pet
if staminacheck = true then
% put code here
end if
end decrease_stamina_pet |
hope it helps, even though it seems your problem was allready solved. |
|
|
|
|
 |
TokenHerbz

|
Posted: Tue Apr 11, 2006 2:32 pm Post subject: (No subject) |
|
|
i try not to use un nessesary variables, it can make you program more probablemfull... |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
ZeroPaladn
|
Posted: Wed Apr 12, 2006 9:18 am Post subject: (No subject) |
|
|
i prefer to use those "unessasary" variables to just turn on and off procedures, it very simple, and easy to toggle them as well. Id rather have something simple (but unessasary to some people) then something overly complicated, yet they do the same thing. |
|
|
|
|
 |
TokenHerbz

|
Posted: Wed Apr 12, 2006 4:49 pm Post subject: (No subject) |
|
|
ZeroPaladan, make a RPG to which you have people telling you specific things according to which quest your on, if you where to use booleans (which i did ) you end up with alot of vraiables, and i don't think they where completly needed, they made my matters confusing, etc: and i always hadda double check the variables was the correct one. |
|
|
|
|
 |
[Gandalf]

|
Posted: Wed Apr 12, 2006 6:09 pm Post subject: (No subject) |
|
|
What's with everyone hating booleans recently? They are great if you are using them correctly. For example:
code: | if whiteToMove then
whiteToMove := not whiteToMove %now we know it's black's turn to move
end if |
Keep in mind that things like:
code: | put 7 > 6 & 5 - 1 = 9 |
and
code: | if wizard.name = "Gonforf" then
wizard.killSelf
end if |
also involve boolean values in some way. |
|
|
|
|
 |
ZeroPaladn
|
Posted: Thu Apr 13, 2006 8:47 am Post subject: (No subject) |
|
|
thanks for the backup [Gandalf]. I will admit that in an RPG those variables make up alot of clutter...
code: | var battlecheck : boolean := false
var itemcheck : boolean := false
var titlescreencheck : boolean := true
% ect... |
...not.
code: | var battlecheck, itemcheck, titlescreencheck : boolean := false
titlescreencheck := true |
|
|
|
|
|
 |
Martin

|
Posted: Thu Apr 13, 2006 9:21 am Post subject: (No subject) |
|
|
ZeroPaladn wrote: thanks for the backup [Gandalf]. I will admit that in an RPG those variables make up alot of clutter...
code: | var battlecheck : boolean := false
var itemcheck : boolean := false
var titlescreencheck : boolean := true
% ect... |
...not.
code: | var battlecheck, itemcheck, titlescreencheck : boolean := false
titlescreencheck := true |
Top one's way easier to read, especially when you want to scan through and find something. Also, the switching the value of titlescreencheck like that is a really bad idea, especially when just a line above you defined it as false, since if the reader only looks until they find where titlescreencheck is set, they'll think it's false.
As for the process bit, keep in mind that you only need to have the value of stamina when you actually need it (to either draw it or use it in a calculation). If you're constantly just calculating and recalculating it, you can optimize your program to make it way more efficient. What I mean by that is that you are decreasing stamina, you can do so using a function of time.
code: | function stamina (start_time : int) : int
return Time.Now - start_time
end |
|
|
|
|
|
 |
ZeroPaladn
|
Posted: Thu Apr 13, 2006 1:35 pm Post subject: (No subject) |
|
|
[quote="TokenHerbz"]ZeroPaladan, make a RPG to which you have people telling you specific things according to which quest your on,...quote]
The fact that you can turn booleans to turn on/off the quests, and jsut incorporate the code into your exisiting game is alot easier. Also makes adding quests much easier too. |
|
|
|
|
 |
TokenHerbz

|
Posted: Thu Apr 13, 2006 3:52 pm Post subject: (No subject) |
|
|
perhaps, but when your dealing with 60+ boolean's, i just think there's an easier way... my save/load procs are nuts :S |
|
|
|
|
 |
|
|