Returning Strings -
TheLazySloth - 22.01.2012
Code:
C:\Users\TheLazySloth\Desktop\San Andreas Multiplayer\Server\TLS-Windows\gamemodes\TheLazySloth.pwn(98) : error 079: inconsistent return types (array & non-array)
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
______________________________
Could not find resulting AMX or its size is under 1byte. ( Probably due to compiler failure )
I get this error when I compile, this is the code that is causing the error...
pawn Code:
stock Load(DataType[], Stat[], For[]) {
if(strcmp(For, "None", true) == 0) {
#pragma unused For
}
if(strcmp(DataType, "serverdata", true) == 0) {
new
Query[128],
Result[128];
format(Query, 128, "SELECT * FROM serverdata LIMIT 1");
mysql_query(Query);
mysql_store_result();
while(mysql_fetch_row_format(Query, "|")) {
if(strcmp(Stat, "Name", true) == 0) {
mysql_fetch_field_row(Result, "Name");
}
if(strcmp(Stat, "Mode", true) == 0) {
mysql_fetch_field_row(Result, "Mode");
}
if(strcmp(Stat, "Map", true) == 0) {
mysql_fetch_field_row(Result, "Map");
}
}
mysql_free_result();
return Result;
}
return false;
}
I am trying to make it so it loads single data and returning the string or value.
Can someone please help? +rep would be rewarded.
Re: Returning Strings -
Sinner - 22.01.2012
You're returning 2 types of data (1 is a string when you return "Result", the other one is a boolean when you return "false"). PAWN expects you to return the same data data type. A possible fix would be:
pawn Code:
stock Load(DataType[], Stat[], For[]) {
new Result[128]; // Gets initialized to NULL
if(strcmp(For, "None", true) == 0) {
#pragma unused For
}
if(strcmp(DataType, "serverdata", true) == 0) {
new Query[128];
format(Query, 128, "SELECT * FROM serverdata LIMIT 1");
mysql_query(Query);
mysql_store_result();
while(mysql_fetch_row_format(Query, "|")) {
if(strcmp(Stat, "Name", true) == 0) {
mysql_fetch_field_row(Result, "Name");
}
if(strcmp(Stat, "Mode", true) == 0) {
mysql_fetch_field_row(Result, "Mode");
}
if(strcmp(Stat, "Map", true) == 0) {
mysql_fetch_field_row(Result, "Map");
}
}
mysql_free_result();
}
return Result; // Returns either the actual result or NULL
}
I hope that made sense, code is untested but should work fine.
Re: Returning Strings -
TheLazySloth - 22.01.2012
What if I want the Value like for playerdata > Money ?
Edit:
NVM I know what to do for when I want Values... just strval(Load("playerdata". "Money", "TheLazySloth"));
The returning of the the Result and the Result only worked, thank you very much sir, +rep for you.
Re: Returning Strings -
Sinner - 22.01.2012
Quote:
Originally Posted by TheLazySloth
What if I want the Value like for playerdata > Money ?
|
I suggest in that case you return it as a string too, then convert it to an integer where you actually need it. You can't return different datatypes in the same function.
Example:
pawn Code:
new Result[128], money;
Result = Load("serverdata", "money", "player"); // Store as a string
money = strval(Result); // Convert to integer
EDIT: Sorry didn't see your edit

No problem
Re: Returning Strings -
TheLazySloth - 22.01.2012
Aha ^^ So yeah thanks