I am currently working on a RPG for the win32 console. I am using a structure to hold information on a player. I was wondering if I could define a structure and declare that structure type right below it in the global declaration area (the area above main()) so that any function I use can modify the struct variable? In my RPG I want to have functions for shops and upgrading, and whenever they upgrade or buy/equip and item I want those functions to be able to modify the struct variable. I was thinking something like this:
I think if that would work it would be the most efficient, and more cipherable, if debuging, method. If anyone knows if this would work, or if you have a suggestion for a better way to store player stats please share!Code:#include <iostream> /* included to show that this is above main()*/ #include <string> /* included to show that this is above main() */ struct stats { char name[50]; int health; int mana; char weapon[50]; char armor[50]; etc... } stats player; int newgame(); int main() { char menu_choice; cout<<"Choose an option:"<<endl; cout<<"(N)ew Game"<<endl; cout<<"(L)oad Game"<<end; cout<<"(E)xit"<<endl; cin>>menu_choice; switch(strlwr(menu_choice)) { case "n": newgame() break; etc... } return 0; } int newgame() { cout<<"Please enter your character's name:" cin>>player.name etc... }![]()



LinkBack URL
About LinkBacks



