Public Group

# Battle System with stats

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

## Recommended Posts

Hey Guys! I'm making alittle feature on my battle system right now. currently it's working with random numbers but still theres a limit ofcourse :-) but I wanna break this limit with level system. but I haven't seen a code with a system that could read in my text (or what everkind of document) f.ex. strength=10 health=250 something like this :-) anybody who can give me just an example of the code that can read these numbers :-D

##### Share on other sites
Offhand:

#include <iostream>#include <fstream>#include <sstream>#include <string>std::istream& parse_line(std::istream& is, std::string& token, int& value){   std::string line;   std::getline(is, line);   std::istringstream iss(line);   std::getline(iss, token, '=');   iss >> value;   return is;}int main(){   std::ifstream file("data.txt");   while(!file.eof())   {      std::string token;      int value;      parse_line(file, token, value);      std::cout << token << " is " << value;   }}

Note that this code is very brittle.

##### Share on other sites
Hi,

you could try an INI Parser. There should be one available for nearly every language.

Check out the Wikipedia Page on INI Files as they have an explanation of the file format as well as links to some libraries.

Good Luck,
ya Storm

##### Share on other sites
Hi Fruny! :-)

I can't really figure out your code :-) I'm using C++ as a language.

Fruny is it possible you can make //comment on the command lines and what they do and why? :-) would help me alot! :-D

btw. Thanks for the help :-D

##### Share on other sites
Quote:
 Original post by Anonymous PosterHi Fruny! :-)I can't really figure out your code :-) I'm using C++ as a language.Fruny is it possible you can make //comment on the command lines and what they do and why? :-) would help me alot! :-Dbtw. Thanks for the help :-D

Uh oh! Sounds like somebody needs to read up on his/her C++. You should at least know what the things are (ie, namespaces, typenames etc); no one expects you to know what they do on first glance, but you should know what they are. Fruny is using the C++ language, in fact, he's using it so well, he's confused you.

Adding support for the // token isn't particularly hard, but it will require more of the same code, so you have to ask yourself, "Do I ask for this code and use it, without knowing what it does or how it works, or do I learn these (very very useful) structures and functions for myself?"

I advise the latter, if only because people aren't going to be holding your hand for your whole life, and whilst they may help you with logic problems, no one's going to code it for you, they'll leave that (and rightly so) up to you! [grin]

There's currently a C++ workshop happening, and there should be a link up the top of these forums. I advise to check it out, it'll go some way to explain what Fruny's coded.

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009468
• ### Who's Online (See full list)

There are no registered users currently online

×