Sign in to follow this  

numbers, and variables

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

This topic is 4380 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this