SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/06/2019, 03:41 PM   #1
Wayzzar
Big Clucker
 
Wayzzar's Avatar
 
Join Date: Dec 2014
Location: Uruguay
Posts: 58
Reputation: 0
Default Problem with data loading

Hi, I've been with this problem for hours without even being able to solve it, I would appreciate a lot if you could help me.

Code explanation: I want 4 slots to appear in the dialog. If the user has a character, the character's name appears and the level that the character has, but if he does not have a character, "Slot vacío" appears.

Code:
new dialog[280], string[128];
	
format(string, sizeof(string), "Nombre\tNivel\n\
");
strcat(dialog, string);

for(new i = 0; i < 4; i++)
{
    new Slot = NickInfo[playerid][nickPJ][i];
    if(Slot == 0)
    {
        format(string, sizeof(string), "{FFFFFF}Slot vacío\t\n\
	");
    }
    else
    {
	format(string, sizeof(string), "{FFFFFF}%s\t(%d)\n\
	", NickInfo[playerid][nickPJ][i], NickInfo[playerid][nickNivelPJ][i]);
    }
    strcat(dialog, string);
}

ShowPlayerDialog(playerid, 2, DIALOG_STYLE_TABLIST_HEADERS, "Seleccionar personaje", dialog, "Seleccionar", "Salir");
Here I show everything related to NickInfo:

Code:
enum nickInfo
{
    nickName[64],
    nickClave[64],
    nickMail[128],
    nickPremium[4],
    nickPJ[4],
    nickNivelPJ[4],
};
new NickInfo[MAX_PLAYERS][nickInfo];

forward OnPlayerLoginClave(playerid, clave[]);
public OnPlayerLoginClave(playerid, clave[])
{
new EscapedText[128], Query[180], content[64];
    mysql_real_escape_string(clave, EscapedText);
    format(Query,sizeof(Query),"SELECT * FROM nicknames WHERE email = '%s' AND clave = '%s'", NickInfo[playerid][nickMail], EscapedText);
    mysql_query(1, Query);
    mysql_store_result();
    
    cache_get_field_content(0, "nickname", content);
	format(NickInfo[playerid][nickName], 32, "%s", content);
	
    NickInfo[playerid][nickPremium] = cache_get_field_content_int(0, "premium");
	
    cache_get_field_content(0, "pj_1", content);
	format(NickInfo[playerid][nickPJ][0], 32, "%s", content);
	cache_get_field_content(0, "pj_2", content);
	format(NickInfo[playerid][nickPJ][1], 32, "%s", content);
	cache_get_field_content(0, "pj_3", content);
	format(NickInfo[playerid][nickPJ][2], 32, "%s", content);
	cache_get_field_content(0, "pj_4", content);
	format(NickInfo[playerid][nickPJ][3], 32, "%s", content);
}
And this is what appears to me. I have registered 2 accounts with different names and I get "NJ" and "J".

https://imgur.com/Ie3YVCi
Wayzzar is offline   Reply With Quote
Old 13/06/2019, 03:53 PM   #2
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 27
Default Re: Problem with data loading

Okay, nickPJ is the name as string?
The thing with multidimensional strings is, you have to add a dimension for string length:
Code:
nickPJ[4][32],
Well explained here: https://forum.sa-mp.com/showthread.php?t=318212
Plastikmensch is offline   Reply With Quote
Old 13/06/2019, 04:43 PM   #3
Wayzzar
Big Clucker
 
Wayzzar's Avatar
 
Join Date: Dec 2014
Location: Uruguay
Posts: 58
Reputation: 0
Default Re: Problem with data loading

Quote:
Originally Posted by Plastikmensch View Post
Okay, nickPJ is the name as string?
The thing with multidimensional strings is, you have to add a dimension for string length:
Code:
nickPJ[4][32],
Well explained here: https://forum.sa-mp.com/showthread.php?t=318212
Can I do that in an enum? I've tried and I get errors

PHP Code:
enum nickInfo
{
    
nickName[64],
    
nickClave[64],
    
nickMail[128],
    
nickPremium[4],
    
nickPJ[4][32], (line 40)
    
nickNivelPJ[4],
}; (
line 42)
new 
NickInfo[MAX_PLAYERS][nickInfo]; 
Code:
C:\Users\user\Desktop\SC-RP\gamemodes\gamemode.pwn(40) : error 001: expected token: "}", but found "["
C:\Users\user\Desktop\SC-RP\gamemodes\gamemode.pwn(42) : error 010: invalid function or declaration
Wayzzar is offline   Reply With Quote
Old 13/06/2019, 05:14 PM   #4
SiaReyes
Gangsta
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 618
Reputation: 57
Default Re: Problem with data loading

Code:
enum nickInfo 
{ 
    nickName[64], 
    nickClave[64], 
    nickMail[128], 
    nickPremium[4], 
    nickPJ[4][32], 
    nickNivelPJ[4]  // no usage of comma here!
};
SiaReyes is offline   Reply With Quote
Old 13/06/2019, 05:27 PM   #5
Wayzzar
Big Clucker
 
Wayzzar's Avatar
 
Join Date: Dec 2014
Location: Uruguay
Posts: 58
Reputation: 0
Default Re: Problem with data loading

Quote:
Originally Posted by SiaReyes View Post
Code:
enum nickInfo 
{ 
    nickName[64], 
    nickClave[64], 
    nickMail[128], 
    nickPremium[4], 
    nickPJ[4][32], 
    nickNivelPJ[4]  // no usage of comma here!
};

I get the same mistakes as if I put the comma

Code:
C:\Users\user\Desktop\SC-RP\gamemodes\gamemode.pwn(40) : error 001: expected token: "}", but found "["
C:\Users\user\Desktop\SC-RP\gamemodes\gamemode.pwn(42) : error 010: invalid function or declaration
Wayzzar is offline   Reply With Quote
Old 13/06/2019, 05:49 PM   #6
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 27
Default Re: Problem with data loading

Oh, I learned something new today: Multidimensional arrays don't work in enums.
Okay, makes sense but still is... ugh.

Well, then the simplest solution is to create 4 strings.
Code:
enum nickInfo
{
   nickPJ1[32],
   nickPJ2[32],
   nickPJ3[32],
   nickPJ4[32]
}
Plastikmensch is offline   Reply With Quote
Old 13/06/2019, 06:12 PM   #7
Wayzzar
Big Clucker
 
Wayzzar's Avatar
 
Join Date: Dec 2014
Location: Uruguay
Posts: 58
Reputation: 0
Default Re: Problem with data loading

Quote:
Originally Posted by Plastikmensch View Post
Oh, I learned something new today: Multidimensional arrays don't work in enums.
Okay, makes sense but still is... ugh.

Well, then the simplest solution is to create 4 strings.
Code:
enum nickInfo
{
   nickPJ1[32],
   nickPJ2[32],
   nickPJ3[32],
   nickPJ4[32]
}
I had also thought about that solution, I think it's the only one for the moment.
But the problem is: how do I select the corresponding nickPJ in (for(new i = 0; i < 4; i++))?
Wayzzar is offline   Reply With Quote
Old 13/06/2019, 06:58 PM   #8
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 27
Default Re: Problem with data loading

You can't, you have to rewrite it.
Or you save the name in another array and use the index:
Code:
new nickPJ[MAX_PLAYERS][4][32];

Last edited by Plastikmensch; 13/06/2019 at 06:58 PM. Reason: fixed typo
Plastikmensch is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in loading data [MYSQL] HoussemGaming Scripting Help 8 25/06/2017 12:45 AM
Problem with MySQL Data Loading Slepur Scripting Help 4 04/08/2013 10:41 PM
Problem with data loading Micius Scripting Help 2 31/07/2013 02:13 PM
MySQL r7 - problem with loading data v3ron Scripting Help 0 28/03/2013 02:15 PM
Big loading data problem admantis Scripting Help 7 17/04/2012 09:14 PM


All times are GMT. The time now is 02:47 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.