nesting issues

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
Paradan
Posts: 16
Joined: Wed May 18, 2011 5:45 pm

nesting issues

Post by Paradan »

Ive tried this a couple ways now and it acts strangely either way

Code: Select all

int roll(int sides)
{
  return (rnd()*sides)+1;
}



void attackType()
{
    switch(roll(2))
      {
        case 1:(swingType = 0);
        break;
        case 2:(swingType = 1);
        break;
      }
}

void location()
{
    switch(swingType)
      {
        case 0: switch(roll(6))
                  {
                    case 1:
                    break;
                    case 2: (hitLocation = 14);
                    break;
                    case 3: (hitLocation = 9);
                    break;
                    case 4: (hitLocation = 11);
                    break;
                    case 5: (hitLocation = 12);
                    break;
                    case 6: (hitLocation = 13);
                    break;
                  }
         break;
         case 1: switch(roll(6))
                  {
                    case 1: (hitLocation = 6);
                    break;
                    case 2: (hitLocation = 8);
                    break;
                    case 3: (hitLocation = 9);
                    break;
                    case 4: (hitLocation = 15);
                    break;
                    case 5: (hitLocation = 16);
                    break;
                    case 6: (hitLocation = 17);
                    break;
                  }
          break;
      }
}

i have a key press doing this

Code: Select all

attackType();
location();


trace("swing"+intToStr(swingType));
trace("location"+intToStr(hitLocation));


when swing type 0 comes up it gives location values from swing 1s case.

did the same thing with nested ifs.
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:o

Even though you've made a little mistake ( swingType = 0, case 1 shouldn't have a break ), it looks like you've discovered a parser bug!

Change the location function to this for now.

Code: Select all

void location()
{
  int C = roll(6);

  switch(swingType)
  {
    case 0: switch(C)
    {
      case 1:
      case 2: hitLocation = 14; break;
      case 3: hitLocation =  9; break;
      case 4: hitLocation = 11; break;
      case 5: hitLocation = 12; break;
      case 6: hitLocation = 13; break;
    }
    break;

    case 1: switch(C)
    {
      case 1: hitLocation =  6; break;
      case 2: hitLocation =  8; break;
      case 3: hitLocation =  9; break;
      case 4: hitLocation = 15; break;
      case 5: hitLocation = 16; break;
      case 6: hitLocation = 17; break;
    }
    break;
  }
}
Hopefully Ville can fix the problem.

K
Paradan
Posts: 16
Joined: Wed May 18, 2011 5:45 pm

Post by Paradan »

woo hoo I contributed.

thanks again.
User avatar
VilleK
Site Admin
Posts: 2371
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I tried to reproduce the problem but failed to do so. When does it occur?

I set swingtype to zero and always get the first switch-statement, and the second when setting it to one.
User avatar
VilleK
Site Admin
Posts: 2371
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Kjell sent me an example that made the bug obvious. It is now fixed and checked in, and also the beta release is updated.
Paradan
Posts: 16
Joined: Wed May 18, 2011 5:45 pm

Post by Paradan »

Ill check out the beta, thnks a bunch
Post Reply