help with BINGO! ! !

Non-platform specific questions.

help with BINGO! ! !

Postby KILILIMAN » Tue May 10, 2011 6:05 am

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.....
KILILIMAN
 
Posts: 6
Joined: Sat May 07, 2011 7:24 am
Score: 0 Give a positive score

Re: help with BINGO! ! !

Postby rykein » Tue May 10, 2011 6:12 am

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;
}
rykein
 
Posts: 63
Joined: Mon Jul 26, 2010 7:26 am
Score: 6 Give a positive score

Re: help with BINGO! ! !

Postby KILILIMAN » Tue May 10, 2011 6:19 am

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...
KILILIMAN
 
Posts: 6
Joined: Sat May 07, 2011 7:24 am
Score: 0 Give a positive score

Re: help with BINGO! ! !

Postby jimmynewguy » Wed May 11, 2011 12:27 am

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;
}
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: help with BINGO! ! !

Postby skydereign » Wed May 11, 2011 12:41 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: help with BINGO! ! !

Postby KILILIMAN » Wed May 11, 2011 5:43 am

Thank you to everybody....
Tomorrow I will try you code skydereign....
Good nigths to everybody jajaaajaja
KILILIMAN
 
Posts: 6
Joined: Sat May 07, 2011 7:24 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest