SA-MP Forums Archive
Array problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Array problem (/showthread.php?tid=77271)



Array problem - Amit_B - 09.05.2009

Hi
I created an trivia system, with questions that I created in array.
Example:
pawn Code:
new triviaQuestions[][5][64] =
{
    {" Question 1?","answer 1","answer 2","answer 3","right answer number"},
    {" Question 2?","answer 1","answer 2","answer 3","right answer number"},
    {" Question 3?","answer 1","answer 2","answer 3","right answer number"},
    {" Question 4?","answer 1","answer 2","answer 3","right answer number"},
    {" Question 5?","answer 1","answer 2","answer 3","right answer number"}
};
But, when I'm trying to read something from this, it's give "".
pawn Code:
new q = random(sizeof(triviaQuestions))
    SendClientMessageToAll(green," Trivia:");
    SendClientMessageToAll(green,triviaQuestions[q][0]);
    //...
It's just send "Trivia:" and "" to all..
I'll be happy if someone will tell me why it's happen and how to fix it.

Thanks.


Re: Array problem - Weirdosport - 09.05.2009

I suggest using an enumerated array:

pawn Code:
enum trivia {
    Question [128],
    Answer1 [50],
    Answer2 [50],
    Answer3 [50],
    Correct
}
Then use:

pawn Code:
new triviaQuestions[][trivia] =
{
    {"Question 1?","answer 1","answer 2","answer 3","1"},
    {"Question 2?","answer 1","answer 2","answer 3","2"},
    {"Question 3?","answer 1","answer 2","answer 3","3"},
    {"Question 4?","answer 1","answer 2","answer 3","2"},
    {"Question 5?","answer 1","answer 2","answer 3","1"}
};