Page 1 of 1

ZLibrary confusion

Posted: Sun Jun 05, 2011 4:43 pm
by Paradan
I cant seem to figure out how to do this,

I want to have a function that rolls a die, and I have a Switch Conditional call that function.

heres what I tried (theres probably a couple of errors in there)

Code: Select all

/* 1.generate target location
   2.roll attack dice
   3.roll defense dice
   4.result hit: play swing,play late parry, gen damage, play blood,knock down,dead
   5.result parry :play half swing , play parry, trade initiative
   6.deplete pools, advance round counter.
*/
int D6()
{
  return round(random(3.5,2.4));
}
//target location
void target()
{
    if (rnd() < 0.5)
    {swingType = 0;}  //diagonal down
    else
    {swingType = 1;}  //midsection

    if (swingType = 0)
    {
      switch(D6)
        {
          case 1: (hitLocation = 1); //upper arm shoulder
          break;
          case 2: (hitLocation = 1); //upper arm shoulder
          break;
          case 3: (hitLocation = 2); //across chest
          break;
          case 4: (hitLocation = 3); //neck
          break;
          case 5: (hitLocation = 4); //face,jaw
          break;
          case 6: (hitLocation = 5); //skull
          break;
        }
    }
}

It's been about twenty years since I tried to do any programing on this scale, so Im kinda rusty.

Posted: Sun Jun 05, 2011 5:35 pm
by Kjell
:roll:

You forgot to put brackets behind the function call from the switch statement. Should have been "switch(D6())" instead of "switch(D6)".

Personally I'd re-write the D6 / dice function like this though ..

Code: Select all

int rollDice(int Sides)
{
	return rnd()*Sides;
}
Also, when you have multiple cases doing the same thing, simply use ..

Code: Select all

	case 1: 
	case 2: hitLocation = 1; //upper arm shoulder 
	break;
Let us know when you have any more questions / problems :wink:

K

Posted: Mon Jun 06, 2011 12:19 am
by Paradan
thank you, and good idea with sides thing.

hopefully ill have a rough prototype up and running in about 2 weeks.