Computer Science Canada Help with my Virtual Pet Program |
Author: | Graeme [ 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 |
Author: | Delos [ Mon Apr 03, 2006 1:49 pm ] | ||||
Post 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:
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...
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. |
Author: | Graeme [ Wed Apr 05, 2006 9:05 am ] | ||
Post 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.. ------------------------------------------------------------------------------------
Thanks again for your help |
Author: | codemage [ Wed Apr 05, 2006 10:39 am ] |
Post subject: | |
You can't define a procedure in another procedure. You can most certainly call a procedure from another procedure though. |
Author: | NikG [ Wed Apr 05, 2006 11:27 am ] |
Post 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). |
Author: | Graeme [ Thu Apr 06, 2006 11:16 am ] |
Post 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 |
Author: | ZeroPaladn [ Tue Apr 11, 2006 1:12 pm ] | ||
Post 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...
hope it helps, even though it seems your problem was allready solved. |
Author: | TokenHerbz [ Tue Apr 11, 2006 2:32 pm ] |
Post subject: | |
i try not to use un nessesary variables, it can make you program more probablemfull... |
Author: | ZeroPaladn [ Wed Apr 12, 2006 9:18 am ] |
Post 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. |
Author: | TokenHerbz [ Wed Apr 12, 2006 4:49 pm ] |
Post 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 ![]() |
Author: | [Gandalf] [ Wed Apr 12, 2006 6:09 pm ] | ||||||
Post subject: | |||||||
What's with everyone hating booleans recently? They are great if you are using them correctly. For example:
Keep in mind that things like:
and
also involve boolean values in some way. |
Author: | ZeroPaladn [ Thu Apr 13, 2006 8:47 am ] | ||||
Post subject: | |||||
thanks for the backup [Gandalf]. I will admit that in an RPG those variables make up alot of clutter...
...not.
|
Author: | Martin [ Thu Apr 13, 2006 9:21 am ] | ||||||
Post subject: | |||||||
ZeroPaladn wrote: thanks for the backup [Gandalf]. I will admit that in an RPG those variables make up alot of clutter...
...not.
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.
|
Author: | ZeroPaladn [ Thu Apr 13, 2006 1:35 pm ] |
Post 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. |
Author: | TokenHerbz [ Thu Apr 13, 2006 3:52 pm ] |
Post 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 |