Page 1 of 1

help with BINGO! ! !

PostPosted: Tue May 10, 2011 6:05 am
by KILILIMAN
Hello my name is christian I'm from mexican, I will try call with us but my english is not very good, so what I will give excuse forward. jajaja...
I'm trying to make a game of Bingo! ! ! but i can't create a script what generate me numbers not repeat, I use the function rand(26).
for example if 6 has been don't be repeat. I wait what you can understand me and help me......
Nice to tell us and I will wait your answers.....

Re: help with BINGO! ! !

PostPosted: Tue May 10, 2011 6:12 am
by rykein
global
Code: Select all
#define MAX 26
int called[MAX];
int index;

int new_num ()
{
int i;
int result;
int temp;

do
{
result=1;
temp=rand(MAX);
for(i=0;i<MAX;i++)
{
if(called[i]==temp)
{
    result=0;
    break;
}
}
}while (result==0);
called[index]=temp;
index++;
return temp;
}

Re: help with BINGO! ! !

PostPosted: Tue May 10, 2011 6:19 am
by KILILIMAN
thank you rykein I will analize the code and I will applicate that....
So really thank you very much
Edit:
I'm put this code in Global
Code: Select all
#define MAX 26
int called[MAX];
int index;

int new_num ()
{
int i;
int result;
int temp;

do
{
result=1;
temp=rand(MAX);
for(i=0;i<MAX;i++)
{
if(called[i]==temp)
{
    result=0;
    break;
}
}
}while (result==0);
called[index]=temp;
index++;
return temp;
}

and I want use the variable "temp" in a press key put this
Code: Select all
switch(temp){
case 0: blablabl
case 1: blalaab
case 2: blalaab}

but say me what "temp" is not defined while is my error...

Re: help with BINGO! ! !

PostPosted: Wed May 11, 2011 12:27 am
by jimmynewguy
declare temp outside the int new_num (). That way it's a global integer and not just a part of the the new_num integer, is an easy way to put it.

Code: Select all
#define MAX 26
int called[MAX];
int index;
int temp;

int new_num ()
{
int i;
int result;

do
{
result=1;
temp=rand(MAX);
for(i=0;i<MAX;i++)
{
if(called[i]==temp)
{
    result=0;
    break;
}
}
}while (result==0);
called[index]=temp;
index++;
return temp;
}

Re: help with BINGO! ! !

PostPosted: Wed May 11, 2011 12:41 am
by skydereign
Well, really the function rykein wrote will return the new number. So, all you would need to do is...
Code: Select all
switch(new_num())
{
    case 0:
    break;

    // etc
}


But declaring it outside will achieve the same thing, but generally outside of gE, global variables are looked down upon.

Re: help with BINGO! ! !

PostPosted: Wed May 11, 2011 5:43 am
by KILILIMAN
Thank you to everybody....
Tomorrow I will try you code skydereign....
Good nigths to everybody jajaaajaja