can anyone look at this and tell me if they can see whats wrong?

This is a discussion on can anyone look at this and tell me if they can see whats wrong? within the Game Programming forums, part of the General Programming Boards category; well, im having this problem that is quite aggrivating. it deals with some coding that is for one of my ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    106

    can anyone look at this and tell me if they can see whats wrong?

    well, im having this problem that is quite aggrivating. it deals with some coding that is for one of my games in c++ (obviously), dos program...not win32. ignore the variable names and see if the syntax is right, please. if anything can find anything wrong with the syntax, please let me know. thanks in advance.

    Code:
    nummoves++;
    if (incroh==1 || inelvencity==1 || inelvenpalace==1 || inminoisland==1) {
         if ((nummoves%5==0) && lvl75mod==1) {
              charhp++;
              if (charhp>=charmaxhp) { charhp=charmaxhp; }
         }
         if ((nummoves%5==0) && lvl75mod==2) {
              charmp++;
              if (charmp>=charmaxmp) { charmp=charmaxmp; }
         }
         if ((nummoves%5==0) && lvl75mod==0) { 
              charhp=charhp; charmp=charmp; 
         }
    }

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    The syntax seems fine, the brackets in these lines


    if (charmp>=charmaxmp) { charmp=charmaxmp; }

    serve no pourpouse though, just do

    if (charmp>=charmaxmp) charmp=charmaxmp;

    are you getting error messages, or is it a logic error inside the game?

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,798
    Looks OK, although I'd probably code it like this:
    Code:
    nummoves++;
    if( (incroh==1 || inelvencity==1 || inelvenpalace==1 || inminoisland==1) && nummoves%5==0 )
    {
        if( lvl75mod == 1 )
            charhp = (++charhp > charmaxhp) ? charmaxhp : charhp;
        else if( lvl75mod == 2 )
            charmp = (++charmp > charmaxmp) ? charmaxmp : charmp;
    }
    The last "if" test you are doing, for lvl75mod==0, isn't needed. It doesn't change the values in the variables.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    that is way more confuseing in my opinion.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    yeah, its logic error. thanks for the suggestions though. im gonna keep dissecting the areas around it later today...not outof school yet

    later, and thanks again

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21