function Richie(player, amount)
{
local q = QuerySQL(db, "SELECT Name,Amount FROM Rich WHERE Name LIKE '"+player.Name+"'");
local cash = GetSQLColumnData( q, 1 ).tostring();
local add = cash + amount;
if (GetSQLColumnData(q,0) == null)
{
QuerySQL(db, "INSERT INTO Rich (Name, Amount) VALUES ('"+player.Name+"', '"+amount.tointeger()+"')");
}
if (GetSQLColumnData(q,0) == player.Name );
{
QuerySQL(db, "UPDATE Rich SET Amount='"+ add+ "' WHERE Name LIKE '" + player.Name + "'");
}
FreeSQLQuery( q );
}
AN ERROR HAS OCCURED [the index 'tostring' does not exist]
CALLSTACK
*FUNCTION [Richie()] Scripts/Functions.nut line [1811]
*FUNCTION [onPlayerCommand2()] Scripts/Commands.nut line [4638]
*FUNCTION [onPlayerChat()] Scripts/DNUS-SQ.nut line [626]
LOCALS
[q] NULL
[amount] 5555
[player] INSTANCE
[this] TABLE
[cash] 5555500
[Pos] INSTANCE
[text] "5555"
[cmd] "donate"
[player] INSTANCE
[this] TABLE
[xp] NULL
2
[text] "!donate 5555"
[player] INSTANCE
[this] TABLE
[SCRIPT] UnLoaded DM/FR
** Shutting down server **
line 1811 is local cash = GetSQLColumnData( q, 1 ).tostring();
The error is quite obvious.
It says:
LOCALS
[q] NULL
That means, your query did not return anything, hence q is NULL.
Since, q is null then obviously, GetSQLColumnData( q, 1 ) is also null.
So, effectively, your code is null.tostring()
Since, there is no method inside NULL defined as "tostring()", the squirrel error that pops up is "the index 'tostring' does not exist"
Quote from: aXXo on May 10, 2016, 10:03 PMThe error is quite obvious.
Unfortunately he probably knows only 3 words in the English language and he will just ignore your post waiting for someone to give a ready to copy-and-paste script.
Quote from: Murdock on May 10, 2016, 10:15 PMQuote from: aXXo on May 10, 2016, 10:03 PMThe error is quite obvious.
Unfortunately he probably knows only 3 words in the English language and he will just ignore your post waiting for someone to give a ready to copy-and-paste script.
What do you mean??????????
if (GetSQLColumnData(q,0) == player.Name );
{
QuerySQL(db, "UPDATE Rich SET Amount='"+ add+ "' WHERE Name LIKE '" + player.Name + "'");
}
What!!!!?.. for anyone that did not see that
if (GetSQLColumnData(q,0) == player.Name ); // [ Really semi colon? ; then a bracket {, maybe I am dumb?]
{
Also that's a really poor use of a local
One method
local Password = HGet( "HSH_Password", player + " Password" ), Level = HGet( "HSH_Level", player.Name + " Level" );
The next method I prefer if I really need any locals
local
Password = HGet( "HSH_Password", player + " Password" ),
Level = HGet( "HSH_Level", player.Name + " Level" );
This is a easy to fix code. I will see how long it takes for you to fix it...
Quote from: Mötley on May 11, 2016, 01:20 AMAlso that's a really poor use of a local
One method
local Password = HGet( "HSH_Password", player + " Password" ), Level = HGet( "HSH_Level", player.Name + " Level" );
The next method I prefer if I really need any locals
local
Password = HGet( "HSH_Password", player + " Password" ),
Level = HGet( "HSH_Level", player.Name + " Level" );
This is a easy to fix code. I will see how long it takes for you to fix it...
didn't get you. What do you mean by saying "Poor use of locals"?
Quote from: Murdock on May 10, 2016, 10:15 PMQuote from: aXXo on May 10, 2016, 10:03 PMThe error is quite obvious.
Unfortunately he probably knows only 3 words in the English language and he will just ignore your post waiting for someone to give a ready to copy-and-paste script.
Yeah, here's your code:
function Shh( player, amount )
{
local q = SomeFunction();/*...*/
local d = GetSQLColumnData( q, 0 );
if( d == null )
{
//control!
return;
}
local yourshit = d + amount;
//Do it here!
}
@KAKAN what I mean by poor use is the fact he had 3 local's when he only needed one.
Example from your script, *You had two locals :P
function Shh( player, amount )
{
local
q = SomeFunction(),
d = GetSQLColumnData( q, 0 );
if( d == null )
{
//control!
return;
}
local yourshit = d + amount;
//Do it here!
}
OR
function Shh( player, amount )
{
local q = SomeFunction(), d = GetSQLColumnData( q, 0 );
if( d == null )
{
//control!
return;
}
local yourshit = d + amount;
//Do it here!
}
I like my method of use as its easier and will look more professional
another test
function Shh( player, amount )
{
local
q = SomeFunction(),
d = GetSQLColumnData( q, 0 ),
c = print( "test"),
e = print( "test"),
f = print( "test"),
g = print( "test"),
h = print( "test"),
i = print( "test"),
j = print( "test"),
k = print( "test"),
z = print( "test");
if( d == null )
{
//control!
return;
}
local yourshit = d + amount;// could be added to the rest of the locals
//Do it here!
}
@Mötley So you're saying that
local myvar = 1, mysz = "String";
is different from
local myvar = 1;
local mysz = "String";
Well then you're wrong, its just a matter of taste.
Its cleaner and much different. Yet you should not have that many locals.
My personal opinion, I think its bad for a server performance to have all of those locals(it adds up quickly)
*It's just not professional
Using the method
local
myvar = 1,
mysz = "String",
a = print( "test"),
b = print( "test"),
c = print( "test"),
e = print( "test"),
f = print( "test"),
g = print( "test"),
h = print( "test"),
i = print( "test"),
j = print( "test"),
k = print( "test"),
z = print( "test");
Is helpful as it will also prevent long locals from running off a screen. causing it to look confusing.
It's good practice. but as quoted you say "it's all about taste", I taste it, taste awful :P :D,..
They're the same amount of variable declarations. It's just a mater of preference and context. Combining them into one statement or using multiple statements does not affect the number of variables that you actually declare.
Thanks wrote that down in my book!
And to prove what I meant:
function A()
{
local var1 = 10;
local var2 = 11;
local var3 = 12;
local var4 = 13;
local locals = getstackinfos(1).locals;
foreach (k, v in locals)
print(k + " : " + v);
print("A----------------");
}
function B()
{
local var1 = 10, var2 = 11, var3 = 12, var4 = 13;
local locals = getstackinfos(1).locals;
foreach (k, v in locals)
print(k + " : " + v);
print("B----------------");
}
A();
B();
[SCRIPT] this : (table : 0x0...)
[SCRIPT] var4 : 13
[SCRIPT] var3 : 12
[SCRIPT] var2 : 11
[SCRIPT] var1 : 10
[SCRIPT] A----------------
[SCRIPT] this : (table : 0x0...)
[SCRIPT] var4 : 13
[SCRIPT] var3 : 12
[SCRIPT] var2 : 11
[SCRIPT] var1 : 10
[SCRIPT] B----------------
We're drifting off a bit here.
@Coolkid as aXXo pointed out, your query fails. It's up to you to figure out why. Go change your script so it actually checks if the query succeeded, and data has been received.
if (GetSQLColumnData(q,0) == player.Name )
{
QuerySQL(db, "UPDATE Rich SET Amount='"+ add+ "' WHERE Name LIKE '" + player.Name + "'");
}
Your problem you added a semicolon
if (GetSQLColumnData(q,0) == player.Name );
{
QuerySQL(db, "UPDATE Rich SET Amount='"+ add+ "' WHERE Name LIKE '" + player.Name + "'");
}
Quote from: Mötley on May 11, 2016, 01:45 PMif (GetSQLColumnData(q,0) == player.Name )
{
QuerySQL(db, "UPDATE Rich SET Amount='"+ add+ "' WHERE Name LIKE '" + player.Name + "'");
}
Your problem you added a semicolon
if (GetSQLColumnData(q,0) == player.Name );
{
QuerySQL(db, "UPDATE Rich SET Amount='"+ add+ "' WHERE Name LIKE '" + player.Name + "'");
}
That's a bug, but it wont cause the error. It's a valid syntax, it just doesn't do what you want it to do.
I already posted the correct answer, let me quote it again:
Quote from: KAKAN on May 11, 2016, 01:59 AMQuote from: Mötley on May 11, 2016, 01:20 AMAlso that's a really poor use of a local
One method
local Password = HGet( "HSH_Password", player + " Password" ), Level = HGet( "HSH_Level", player.Name + " Level" );
The next method I prefer if I really need any locals
local
Password = HGet( "HSH_Password", player + " Password" ),
Level = HGet( "HSH_Level", player.Name + " Level" );
This is a easy to fix code. I will see how long it takes for you to fix it...
didn't get you. What do you mean by saying "Poor use of locals"?
Quote from: Murdock on May 10, 2016, 10:15 PMQuote from: aXXo on May 10, 2016, 10:03 PMThe error is quite obvious.
Unfortunately he probably knows only 3 words in the English language and he will just ignore your post waiting for someone to give a ready to copy-and-paste script.
Yeah, here's your code:
function Shh( player, amount )
{
local q = SomeFunction();/*...*/
local d = GetSQLColumnData( q, 0 );
if( d == null )
{
//control!
return;
}
local yourshit = d + amount;
//Do it here!
}
@Coolkid please, if you can understand English, then you can understand my code too.
Quote from: Coolkid on Apr 26, 2016, 01:50 PMI don't want to be harsh here but I have to
We can't baby sit anymore hwre now this is the easiest prb to be. Solved You cant solve your own problem which solution has been given and telling me you cant solve you solve your easiest problem lol