+ 1

Simple RPG question

I want to make a simple RPG that doesn't use classes since I'm not that far. I want this sort of layout... Def player_creator(): Things that make the player like health and attack points Return [values from function that are in list form NOT tuples] Def battle(player_info): Things happen and player loses health and let's say earns XP Return [new and updated player info in list] Main loop(): Playerstats = (values from player creator and then when needed stats from the battle) .... What I'm trying to ask is, is there a way to create values in one function, return them to a variable in the main loop, have a function take that variable as a parameter and then update the original list or even make a new one?

2nd Feb 2017, 10:27 PM
Nick Ferguson
Nick Ferguson - avatar
2 odpowiedzi
+ 4
rpgs are more difficult than they seem. (i am coding one myself) Doing one without classes would in my mind make the process even more difficult.. anyway onto your question. yes. you will want to create a function for each action that can be performed and pass it the relevant values you wish to work with. i.e playerattack(attackvalue, enemyhealth) return newenemy health. but yeah. I would wait until you learn classes.. maybe try a nice game of mastermind instead 😊
2nd Feb 2017, 10:43 PM
jay
jay - avatar
+ 1
He's right. It is possible but will be a huge mess without structs or better yet, classes. Classes are basically a step up from structs that can contain its own member fuctions. I too am making a small rpg as a side project which involves a map screen and attacking others using a console window. oh and to answer your question about functions returning multiple values, you can use references as the function parameters to directly modify variables. ex. void something(int &arg1, int &arg2);
3rd Feb 2017, 12:11 AM
R- Ry
R- Ry - avatar