Jump to content
  • Advertisement
Sign in to follow this  
jason1

experience points

This topic is 4804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i use the "system("myprogram.exe")" to execute different programs from a main program. how can i make it where once u choose an option so many times it changes to a different program? ex: first time - system("program.exe"). third time - system("program2.exe"). this is all based around fighting and experience points.

Share this post


Link to post
Share on other sites
Advertisement
You can try, I am sure there is a much better and safer way, string manipulation via a pointer.

For example:

...
char Buffer[256]={"myprogram.exe"};
char IntBuffer[8]={0};
sprintf(IntBuffer, "%d", ProgramCount);
strcat(IntBuffer, ".exe");
...
char *place = strstr(Buffer, ".exe");
strcpy(place, IntBuffer);
system(Buffer);




I think I have written down what needs to be utilized.

sprintf changes your next number into a string, strcat appends the extension ".exe" after your number so now you have "#.exe", with # being the number in ProgramCount.

Basically, it takes the "myprogram.exe" and finds where the instance of ".exe" is. Derive a pointer so essentially you have "myprogram" then what the pointer points to in the memory location. Copy, to where the pointer points to, the contents of IntBuffer. Now you have the string "myprogram#.exe", # replaced with whatever ProgramCount contains.

If anybody wants to lead the OP into the "safer" and probably "correct" way, by all means do so.

Share this post


Link to post
Share on other sites
Here's something a little simpler:

std::string exeBasePath = "program";
std::string exeNumber = "";
std::string exeBaseExt = ".exe";
...
if( user selects option one )
{
exeNumber = "1";
}
...
std::string final = exeBasePath + exeNumber + exeBaseExt;
system( final.c_str() );



But I would highly not use a design in which you are calling multiple programs in a game! Instead, you should call functions that would have the same functionality.

Share this post


Link to post
Share on other sites
whats wrong with doing that? besides there not big programs. theyre mostly like 1 option off the menu. like theres a program for fighting and stuff like that but the fighting is simple. it just picks a random number. if its a 1 u win. if its a 2 u lose.

Share this post


Link to post
Share on other sites
Quote:
Original post by jason1
whats wrong with doing that? besides there not big programs. theyre mostly like 1 option off the menu. like theres a program for fighting and stuff like that but the fighting is simple. it just picks a random number. if its a 1 u win. if its a 2 u lose.


Ok it'd be like this, you write new seperate applications for something *that* simple. Everytime you call system, you game stops until the launched program terminates. Now if all it does is pick a number, how do you plan on passing that data back to your game? So overall, that is a generally bad idea&tm;

Instead you will just need to make a function and call that instead. Why? Functions will not completely stop your game and switch focus to another executing application, and keeping track of the data is a lot easier. There's lots of other reasons why, but there's not a single reason why I could advocate making seperate exe's to do what you are aiming for. Good luck!

Share this post


Link to post
Share on other sites
ok thnx. i see what you mean now, but whats another way to make it go back to the menu after the function executes? and also where can i find this stuff at because my book doesnt talk about expierence points and stuff like that. when the book ends it just teaches you how to make a blackjack game.

Share this post


Link to post
Share on other sites
Quote:
Original post by jason1
ok thnx. i see what you mean now, but whats another way to make it go back to the menu after the function executes?


A function always returns to where it was called.

Quote:
and also where can i find this stuff at because my book doesnt talk about expierence points and stuff like that.


What have "experience points" to do with learning the bases of programming? What do you mean by "and stuff like that"? If you want to design a computer RPG, it would help if you had played RPGs before and had an idea of what kind of rules they use - pen and paper RPGs are particularly useful in that respect.

Quote:
when the book ends it just teaches you how to make a blackjack game.


You should first make sure you understand the programming concepts exposed in the book. Then you can go ahead and make up your own game - be creative: you are the one who knows what you want to do with "experience points". Learning to program means learning to translate those ideas into code.

Share this post


Link to post
Share on other sites
Uhh, buddy. No offense but if you don't know what a function is and how it works, you could probably do with learning how to program. Go buy a book on regular programming and learn from that before you try to learn how to program a game.

You need to learn a thing or two about good 'ol sequence, selection, iteration and procedure theory. Program control will normally return to the calling function after a function has finished executing. (At least, it does in every language I've ever programmed in)

Good tutorials and books can be found here:

http://www.gamedev.net/community/forums/topic.asp?topic_id=333728

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!