Jump to content
  • Advertisement
Sign in to follow this  
DeathsBargin

numbers, and variables

This topic is 4685 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

Im not sure how I set a variable to a number(im trying to do it for hp for a text based game.) I need to be able to ad and subtract from the variable at will. I tried int hp hp = 25 it didnt really help (Not to mention im not sure how to subtract/ ad to it.

Share this post


Link to post
Share on other sites
Advertisement
Sorry about the double post but I figure I might aswell just ask these while im here.

I am really having problems with alot of things in making this game.

For example I need to give the person the option to lets say pick up a gun. And also the option to go out of the room.

But first of all I dont want them to answer with (I mean i dont want them to answer that way)
1) Take the gun
2) Leave the room
I want them to answer more like in a MUD

like they type in
take gun
or
go out of room (left etc..)

Share this post


Link to post
Share on other sites
Try this:

int hp = 0;
hp = 25;

// For subtraction
hp -= 10;

Or

hp = hp - 10;

Or if you want to subtract just one.

hp--;

// For addition
hp += 10;

Or

hp = hp + 10;

Or if you want to add just one.

hp++;


Also check this site Cplusplus.com it has a good tutorial I think you should read if your having trouble with variables.

Share this post


Link to post
Share on other sites
Thanks alot (When I tried it i didnt put in the extra =)

but what about this?
For example I need to give the person the option to lets say pick up a gun. And also the option to go out of the room.

But first of all I dont want them to answer with (I mean i dont want them to answer that way)
1) Take the gun
2) Leave the room
I want them to answer more like in a MUD

like they type in
take gun
or
go out of room (left etc..)

Share this post


Link to post
Share on other sites
That is sort of more complicated I think, I have never done it myself personally. You could perhaps devise a set of commands and make your own sort of scripting language or use LUA some how. I really have never done that someone else might be able to help though.

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!