Advertisement

RPG Problems

Started by March 24, 2002 07:47 PM
41 comments, last by Quantrizi 22 years, 8 months ago
Andrew Throws a link:

Cplusplus.com

You realise that arrays can be:

array[12]();

(Or an array can also be a function, a class and every data tyoe at the same time?)

Next, do you know what return does? It gives value to a function, so if a function, lets say:

int k(a)
{
return a;
}

That would mean that k(a) would equal whatever a is as LONG as it is an int. If im not clear tak a look at the link. And, once again, USE FUNCTIONS FOR GOD's SAKE!

[edited by - Andrew Nguyen on March 25, 2002 7:46:33 PM]
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
quote: Original post by Andrew Nguyen
Andrew Throws a link:

Cplusplus.com

You realise that arrays can be:

array[12]();

(Or an array can also be a function, a class and every data tyoe at the same time?)

Next, do you know what return does? It gives value to a function, so if a function, lets say:

int k(a)
{
return a;
}

That would mean that k(a) would equal whatever a is as LONG as it is an int. If im not clear tak a look at the link. And, once again, USE FUNCTIONS FOR GOD''s SAKE!

[edited by - Andrew Nguyen on March 25, 2002 7:46:33 PM]

Ok, I am using functions.....sheesh.......I''m working on it, first got to fix the current bugs.

Advertisement
Quantrizi: don''t mind andrew, he knows as much about programming as my dog (and my dog has been dead for five years already).
the real link is cplusplus.com (gotta have the http:// part)...
as someone else said, you really ought to use classes for some of this... it''ll be some stuff you must learn, but once you get the basics of it you can play around and ask lots of questions here. do you know anything about structs? classes are very similar... basically just a clean pretty way of organizing your data and the functions that manipulate it.
not to get you down, either, but you should re-structure your game... instead of having a LONG ASS bunch of code, giving the player choices, and responding to it, you can basically use a loop in which the game gives output, gets input from the player, and decides what to do:
InitGame(); // function to initialize game, characters, etc...bool gameRunning = true;while(gameRunning)  {  displayOutput();    // shows messages (i.e. "There is a ninja.")  listChoices();      // shows choices (i.e. "1)Attack 2)Run")  getPlayersChoice(); // gets player''s choice  processInput();     // decides what happens based on the last choice  }; 

then the loop keeps looping until you set gameRunning to false somewhere (when the player dies or quits)...
hope that helps more than it confuses you
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Ok, the only thing I don''t get is the gamerunning thing, do you input everytime, or just once.

Looking for love ends up in pain, not looking for pain ends up in love
gameRunning in my example is just a boolean variable that keeps the while loop running until the game is over... as long as gameRunning == true you will continue to get the output and be asked for your actions.
seriously, check out cplusplus.com, it is a fairly short tutorial that will put you in the right direction with functions and control structures and all the other nice things that keep your code from becoming a convoluted mess.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Ok, thanx. I''ll start work on it right now.
Advertisement
I have a question about the game running thing. When that while loop calls a function, do you have to wait for the function to return for the loop to end? Like, if it calls a function to do something, and lets say that function either makes gamerunning = false in the middle of it, or calls another function and that does something and makes gamerunning = false. I need to know because I''m starting on the story and stuff of my RPG, and I have it where the player can choose his attack, use items and battle and so on.
HibikiWheres the any key?www.geocities.com/dragongames123/home.html
find your elementat mutedfaith.com.<º>
quote: Original post by Andrew Nguyen
(Or an array can also be a function, a class and every data tyoe at the same time?)

WTF are you talking about?
Yes, you would have to wait until the end of the loop for the check to occur again.

If you're worried about stuff continuing to progress after gameRunning is set to false, there are some easy solutions. You could put a check...

if (gameRunning == false)
return;

... at the starting of your main functions. I don't know if I would progress these checks all the way down into every function in your game. For the top-level functions it makes sense. For the lower-level ones, you can just have a standard return value that signifies and error or something, and let the top-level functions (such as listChoices() in this case) handle setting gameRunning to false.

For example...

displayOutput() and any child functions execute normally and returns without error.

listChoices() is called, and starts execution (since gameRunning is still true), but one of its child functions gets an error, and returns.. say, -1. listChoices() notices this, sets gameRunning to false, and returns.

When getPlayersChoice() and processInput() are called, they both check right away if gameRunning is false, and since it is, they return control, doing nothing. Then the end of the loop is reached, and exited.

[edited by - SantaClaws on March 28, 2002 2:20:09 PM]
Ok, I''ve re-done the whole source to make it use void blahblahblah() and stuff, but I have a question. With voids, do you do it like this:
void town()
{
cout << "Welcome";
}

or what....I keep on getting errors. I made a *.hpp to include of my voids:
void battle();
void main();
etc...

I include that using #include "void.hpp"(which is my void header name)

But my Dev-C++ 4.9.1.0 always says File not found, it''s also in the same directory.

This topic is closed to new replies.

Advertisement