.tostring doesnot exist

Started by Coolkid, May 10, 2016, 09:42 PM

Previous topic - Next topic

Coolkid

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();

aXXo

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"

Murdock

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.

Coolkid

Quote from: Murdock on May 10, 2016, 10:15 PM
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.
What do you mean?????????? 

Mötley

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...

KAKAN

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 PM
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.
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!
}
oh no

Mötley

#6
@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!
}


DizzasTeR

@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.

Mötley

#8
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.
.

Mötley

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----------------
.

Thijn

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.

Mötley


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 + "'");
}

Thijn

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.