• 13
• 18
• 19
• 27
• 9

experience points

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

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 on other sites
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 on other sites
that was way too confusing . maybe ill just forget about it.

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 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 on other sites
Yeah- Unless there is a really, really, good reason, I would use a function instead.

Share on other sites
Quote:
 Original post by jason1whats 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 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 on other sites
Quote:
 Original post by jason1ok 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 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