Jump to content
  • Advertisement
Sign in to follow this  
Xsis

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.

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
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


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.

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!