SA-MP Forums Archive
Defining help - 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)
+--- Thread: Defining help (/showthread.php?tid=391499)



Defining help - Larry123 - 10.11.2012

Hello

I have a problem.

I want to use variables like this:

PlayerInfo[playerid][ContactName][0] = "Test";
PlayerInfo[playerid][ContactNumber][0] = 5456;

Code:
enum pInfo
{
     ContactNumber[15], // 15 int variables made
     ContactName[30][15], // 15 string variables, but.. i get error(This is line 386)
}; [//Line 387
new PlayerInfo[50][pInfo];
Error:

C:\Users\...\Desktop\samp03e_svr_R2_win32\gamemode s\...(386) : error 001: expected token: "}", but found "["
C:\Users\...\Desktop\samp03e_svr_R2_win32\gamemode s\...(387) : error 010: invalid function or declaration


So how can i resolve this problem?


Re: Defining help - Konstantinos - 10.11.2012

pawn Code:
enum pInfo
{
     ContactNumber[15],
     ContactName[30][15] // on the last, we don't use ","
};
new PlayerInfo[50][pInfo];



Re: Defining help - Larry123 - 10.11.2012

It didn`t help, the thing is that there are ContactName[30][15]. Two []. That`s wrong i think, but how i resolve this.


Re: Defining help - Larry123 - 10.11.2012

Bring Up My Post, because i need help very fast, because i got errors because of it, and all i can do is waiting:P Someone knows the solution?


Re: Defining help - ViniBorn - 10.11.2012

pawn Code:
PlayerInfo[playerid][ContactName][0] = "Test"; // or format
PlayerInfo[playerid][ContactNumber] = 5456;



Re: Defining help - Steven82 - 10.11.2012

This doesn't work.

pawn Code:
PlayerInfo[playerid][ContactName][0] = "Test";
You're going to have to use the format function for this.

pawn Code:
format(PlayerInfo[playerid][ContactName][0], 30, "Test");  // change test the names.



Re: Defining help - Larry123 - 10.11.2012

I`m going to use it like this:

PlayerInfo[playerid][ContactName][0] = "My0Contact";
PlayerInfo[playerid][ContactName][1] = "My1Contact";
PlayerInfo[playerid][ContactNumber[0] = 3555;
PlayerInfo[playerid][ContactNumber[1] = 43267;

But the problem is in definition.

They are defined like this:
Code:
enum pInfo
{
     ContactNumber[15], // 15 int variables made
     ContactName[30][15], // 15 string variables, (30 is lenght of string) but.. i get error(This is line 386)
}; //Line 387
new PlayerInfo[50][pInfo];
But in definition i get this errors:

C:\Users\...\Desktop\samp03e_svr_R2_win32\gamemode s\...(386) : error 001: expected token: "}", but found "["
C:\Users\...\Desktop\samp03e_svr_R2_win32\gamemode s\...(387) : error 010: invalid function or declaration



// EDIT

Testing again


Re: Defining help - Steven82 - 10.11.2012

Use my method above.


Re: Defining help - Larry123 - 10.11.2012

Are you sure the problem is in using not in definition?


AW: Re: Defining help - Nero_3D - 10.11.2012

Quote:
Originally Posted by Larry123
View Post
Are you sure the problem is in using not in definition?
It is, didnt noticed it in the other topic

You can only use one dimension within enum because an enum is just a list of constant variables!

The easist way would be to create a new array
pawn Code:
#define MAX_CONTACTS (15)

enum cInfo {
     ContactNumber,
     ContactName[30]
};
new ContactInfo[sizeof PlayerInfo][MAX_CONTACTS][cInfo];