How are you declaring this array of lottery_type? I see a reference to
(maxlottery), but if you want players to be able to buy more than 1
ticket, wouldn't putting a maxlottery value to make an array with sort
of inhibit the player from buying all the tickets he wants? You should
instead turn that array into a linked list, and make the int slot1,
slot2, and slot3 an array of int slot[3] within the structure, then do
something like this:

bool winner;
int count = 0;
char buf[MAX_STRING_LENGTH];

for ( lotto = lottery_list; lotto != NULL; lotto = lotto->next )
{
    winner = TRUE;

    for ( x = 0; x < 3; x++ )
        if ( lotto->slot[x] != num[x] )
        {
            winner = FALSE;
            break;
        }

    if ( winner )
    {
        sprintf(buf,"%s is a winner!\n\r", lotto->name);
        info (ch,0,buf);
        count++;
    }
}

or something like that... that way the thing wouldn't just stop when it
hit the first winner in the array or list, in case more than one person
bought a winning ticket (I'd hate to win the lotto and then find out
someone else had bought their ticket before me and so I actually won 0
:D), and keeps track of the # of people that won so that you can split
the jackpot up accordingly... you'll probably also want to make sure the
winner is online, and either they forfeit their winnings if they're not,
or you load the pfile, credit them, and unload their pfile... hope this
gets you going in the right direction... to find out where your current
array is getting hosed, load gdb, break it on the loading routine, make
sure that when it's done loading everyone's data that the array contents
are still valid (before it exits the function) and then put a watch on
the array to see when it's altered... anyway, hope this helps...

wavewave
Richard Lindsey.

-----Original Message-----
From: Mervine, Keith [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 10, 2004 1:01 PM
To: [email protected]
Subject: Problem with an array

Hi,
        I am working on a "daily lottery" system and wanted people to be
able to buy more than one ticket. (So I opted not to use the pfiles)

Right now Im saving the data in a file in this
format...(playerlottery.txt)

2
Thalor~
1 1 1             <--- for testing purposes I have the lotto always
generate 1 1 1 for now.
Grok~
9 6 7

(maxlottery)
(Name)~
(slot1) (slot2) (slot3)
(Name)~
(slot1) (slot2) (slot3)


I can load, save and add new ones to this file using a structure:

struct lottery_type
{
    char *    name;
    int       slot1;
    int       slot2;
    int       slot3;

};

The problem comes when I generate the lottery, somewhere in between the
loading of the lottery tickets and the comparison the array goes all
hooey....what am I doing wrong?

void do_generate(CHAR_DATA *ch)
{
  int num1, num2, num3;
  int pnum1, pnum2, pnum3;
  int i;
  LOTTERY_DATA *lottery;

  num1 = dice(1,1);
  num2 = dice(1,1);  //Testing all will be 0,9
  num3 = dice(1,1);

  for (i=0;i<maxLottery;i++)
  {
   pnum1 = lottery[i].slot1;
   pnum2 = lottery[i].slot2;
   pnum3 = lottery[i].slot3;

   if (pnum1 == num1 && pnum2 == num2 && pnum3 == num3)
   {
    info (ch,0,"We have a winner!\n\r");
   }
  }
}

Using GDB I look at pnum1 pnum2 and pnum3 and they turn into something
like 824193073


Any help would be ...well...helpful!

Thanks!

-K

-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to