ERROR: Must be assigned to an array | with random messages -
Яσскѕтая - 21.07.2010
I was trying to make it so it sends random messages and the player has to type that answer but when I compile it I get these errors
pawn Code:
C:\Servers\SA-MP\gamemodes\MS.pwn(1977 -- 1978) : error 006: must be assigned to an array
C:\Servers\SA-MP\gamemodes\MS.pwn(1978 -- 1979) : error 006: must be assigned to an array
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Errors.
Lines
pawn Code:
public NewContest()
{
new string[128]; //We're creating a new string here to inform players of the new number.
ContestAnswer = randomAnswer //Line 1977
CONTEST_PRIZE = randomMoney // Line 1978
format(string,sizeof string,"The first person to type '%d' first, wins $%d.",ContestAnswer,CONTEST_PRIZE); // Line 1979
SendClientMessageToAll(COLOR_CONTEST,string);
return 1;
}
randomAnswer and randomMoney
pawn Code:
new randomAnswer[][0] =
{
{"Movie server lives!"},
{"Cobra is a hoe!"},
{"Mr.Beer is a hoe!"},
{"Sh4d0w is a hoe!"}
};
new randomMoney[][]=
{
{4000},
{2000},
{100},
{10000},
{1}
};
Re: ERROR: Must be assigned to an array | with random messages -
ikey07 - 21.07.2010
try this one
pawn Code:
new randomAnswer[4][128] = {
{"Movie server lives!"},
{"Cobra is a hoe!"},
{"Mr.Beer is a hoe!"},
{"Sh4d0w is a hoe!"}
};
new randomMoney[5][0]= {
{4000},
{2000},
{100},
{10000},
{1}
};
public NewContest()
{
new string[256];
new ContestAnswer[256];
new rand = random(sizeof(randomAnswer));
strmid(ContestAnswer,randomAnswer[rand],0,strlen(randomAnswer[rand]),255);
new rand2 = random(sizeof(randomMoney));
new CONTEST_PRIZE = randomMoney[rand2];
format(string,sizeof string,"The first person to type '%s' first, wins $%d.",ContestAnswer[rand],CONTEST_PRIZE);
SendClientMessageToAll(COLOR_CONTEST,string);
return 1;
}
EDIT, now its fixed
Re: ERROR: Must be assigned to an array | with random messages -
Яσскѕтая - 21.07.2010
pawn Code:
C:\Servers\SA-MP\gamemodes\MS.pwn(1975) : warning 219: local variable "ContestAnswer" shadows a variable at a preceding level
C:\Servers\SA-MP\gamemodes\MS.pwn(1979) : warning 219: local variable "CONTEST_PRIZE" shadows a variable at a preceding level
C:\Servers\SA-MP\gamemodes\MS.pwn(1979) : error 033: array must be indexed (variable "-unknown-")
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Error.
I already had Contest Answer defined and Contest prize, should I move those news to where I have them defined?
EDIT: When moved to the top pawncc crashed, when removed the top ones and do what you said I get this
pawn Code:
C:\Servers\SA-MP\gamemodes\MS.pwn(1162) : error 017: undefined symbol "ContestAnswer"
C:\Servers\SA-MP\gamemodes\MS.pwn(1976) : error 033: array must be indexed (variable "-unknown-")
C:\Servers\SA-MP\gamemodes\MS.pwn(2002) : error 017: undefined symbol "CONTEST_PRIZE"
C:\Servers\SA-MP\gamemodes\MS.pwn(2004) : error 017: undefined symbol "CONTEST_PRIZE"
C:\Servers\SA-MP\gamemodes\MS.pwn(2005) : error 017: undefined symbol "ContestAnswer"
C:\Servers\SA-MP\gamemodes\MS.pwn(2005) : warning 215: expression has no effect
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
5 Errors.
Re: ERROR: Must be assigned to an array | with random messages -
ikey07 - 21.07.2010
if you dont use ContestAnswer and CONTEST_PRIZE in nowhere else, than you should put both new under NewConest,
and here is onemore thing, use this line
pawn Code:
format(string,sizeof(string),"The first person to type '%s' first, wins $%d.",ContestAnswer[rand],CONTEST_PRIZE);
Re: ERROR: Must be assigned to an array | with random messages -
Яσскѕтая - 21.07.2010
I do use it in another place.
pawn Code:
public OnPlayerWinContest(playerid)
{
new pName[MAX_PLAYER_NAME],string[128]; // A pName variable for the player's name, and a string to output.
GetPlayerName(playerid,pName,sizeof pName); //Get's the player's name.
format(string,sizeof string,"Player %s has won the contest and has won %d!",pName,CONTEST_PRIZE);
SendClientMessageToAll(0x00FFFFFF,string); //Same color, and it outputs a string.
GivePlayerMoney(playerid,CONTEST_PRIZE);
ContestAnswer = -1;
return 1;
}
pawn Code:
public OnPlayerText(playerid, text[])
{
if(strval(text) == ContestAnswer && ContestAnswer != -1)
{
OnPlayerWinContest(playerid);
}
Re: ERROR: Must be assigned to an array | with random messages -
ikey07 - 21.07.2010
ok, now its working
and
pawn Code:
new CONTEST_PRIZE = randomMoney[rand2][0];
Re: ERROR: Must be assigned to an array | with random messages -
Яσскѕтая - 21.07.2010
I am still getting the errors, this is my full script for it:
Top of script
pawn Code:
new randomAnswer[4][128] = {
{"Movie server lives!"},
{"Cobra is a hoe!"},
{"Mr.Beer is a hoe!"},
{"Sh4d0w is a hoe!"}
};
new randomMoney[5][1]= {
{4000},
{2000},
{100},
{10000},
{1}
};
new ContestAnswer;
new CONTEST_PRIZE;
The forwards
pawn Code:
Using NewContest();
Using OnPlayerWinContest(playerid);
OnGameModeInit
pawn Code:
SetTimer("NewContest",(1000*60*CONTESTTIME),1);
OnPlayerText
pawn Code:
if(strval(text) == ContestAnswer)
{
OnPlayerWinContest(playerid);
}
NewContest
pawn Code:
public NewContest()
{
new string[256];
strmid(ContestAnswer,randomAnswer[rand],0,strlen(randomAnswer[rand]),255);
format(string,sizeof(string),"The first person to type '%s' first, wins $%d.",ContestAnswer[rand],CONTEST_PRIZE);
SendClientMessageToAll(COLOR_CONTEST,string);
return 1;
}
OnPlayreWinContest
pawn Code:
public OnPlayerWinContest(playerid)
{
new pName[MAX_PLAYER_NAME],string[128]; // A pName variable for the player's name, and a string to output.
GetPlayerName(playerid,pName,sizeof pName); //Get's the player's name.
format(string,sizeof string,"Player %s has won the contest and has won %d!",pName,CONTEST_PRIZE);
SendClientMessageToAll(0x00FFFFFF,string); //Same color, and it outputs a string.
GivePlayerMoney(playerid,CONTEST_PRIZE);
ContestAnswer = -1;
return 1;
}
Ok so now using all that when compiling pawncc crashes.
Re: ERROR: Must be assigned to an array | with random messages -
ikey07 - 21.07.2010
You CANNOT get text out of digits !!
OnText
pawn Code:
if(strcmp(text,ContestAnswer, true ) == 0 )
{
OnPlayerWinContest(playerid);
}
OnWIn
pawn Code:
ContestAnswer = "sdashdgjsj hgjsdhgjhasgdjcgjsadhgsjhxћ";
so the player can't get OnPlayerWin.
Timer also you have 1h*CONTESTTIME = A lot of time
Never mix text and value, any text as digit == 0
Re: ERROR: Must be assigned to an array | with random messages -
Яσскѕтая - 21.07.2010
The contest time is 3 minutes.
And ok its working except its saying "The first person to type " wins $0"
Re: ERROR: Must be assigned to an array | with random messages -
ikey07 - 21.07.2010
1000*60*CONTESTTIME = 3 minutes? O.o