Skip to main content
GameDev.net gamedev.net
🔒 Locked

operator problems??

Started by demonrealms Feb 19, 2003 at 9:18 PM 3 replies 500+ views
Original Post
demonrealms
demonrealms
Hey, I''m having trouble with creature life. I typed this in: if(creature1.mlife <= 0) { cout << "he''s dead" << endl; cmd2(); } else { cmd3(); } But when i execute the program. It just kills it no matter what. And the creature.mlife = 120; your damage = 34; so it can''t be overkill. Does sanyone know my problem??
GeniX
GeniX
You could try a lazy debugging method

Put a ''cout'' statement before the ''if'' and display the creature1.mlife - from your little description, I''m betting that when the execution gets to the ''if'' statement, creature1.mlife has a value less than or equal to 0.

Then shift the cout statement earlier and earlier in the execution path until you find where its going screwy.

Yes - lazy debug method. I should be ashamed for recommending it first



regards,

GeniX

www.cryo-genix.net
regards,GeniXwww.cryo-genix.net
demonrealms
demonrealms
sorry, i should hae been more clear i ment i mean when i shoot it it klls it no matter what.
string cmd;
cout << ": ";
cin >> cmd;
if (cmd == "shoot")
{
cout << "you shot the monster!" << endl;
(creature1.mlife - charicter.total_dam);
if(creature1.mlife <= 0) { cout << "he''s dead!"; cmd2();}
else
{cmd1();}
GeniX
GeniX
For starters, where you subtract your creatures life, is wrong...
you want something like:

creature1.mlife = (creature1.mlife - charicter.total_dam);

or

creature1.mlife -= charicter.total_dam;

--

Once more, make very sure that your creature1.mlife is initialised to a suitable value prior to your shooting code, and also that your charicter.total_dam is likewise initialised to a suitable value prior to your shooting code.

Im assuming that mlife and total_dam are basic numeric types like ints, floats or such, and not pointers?



regards,

GeniX

www.cryo-genix.net
regards,GeniXwww.cryo-genix.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.