Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Coolkid on May 10, 2016, 09:42 PM

Title: .tostring doesnot exist
Post by: Coolkid on May 10, 2016, 09:42 PM
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();
Title: Re: .tostring doesnot exist
Post by: aXXo on May 10, 2016, 10:03 PM
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"
Title: Re: .tostring doesnot exist
Post by: 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.
Title: Re: .tostring doesnot exist
Post by: Coolkid on May 10, 2016, 11:07 PM
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?????????? 
Title: Re: .tostring doesnot exist
Post by: Mötley on May 11, 2016, 01:20 AM
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...
Title: Re: .tostring doesnot exist
Post by: KAKAN on May 11, 2016, 01:59 AM
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!
}
Title: Re: .tostring doesnot exist
Post by: Mötley on May 11, 2016, 03:00 AM
@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!
}

Title: Re: .tostring doesnot exist
Post by: DizzasTeR on May 11, 2016, 04:00 AM
@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.
Title: Re: .tostring doesnot exist
Post by: Mötley on May 11, 2016, 04:51 AM
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,..
Title: Re: .tostring doesnot exist
Post by: . on May 11, 2016, 05:09 AM
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.
Title: Re: .tostring doesnot exist
Post by: Mötley on May 11, 2016, 05:13 AM
Thanks wrote that down in my book!
Title: Re: .tostring doesnot exist
Post by: . on May 11, 2016, 05:34 AM
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----------------
Title: Re: .tostring doesnot exist
Post by: Thijn on May 11, 2016, 06:03 AM
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.
Title: Re: .tostring doesnot exist
Post by: Mötley on May 11, 2016, 01:45 PM

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 + "'");
}
Title: Re: .tostring doesnot exist
Post by: Thijn on May 11, 2016, 04:10 PM
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.
Title: Re: .tostring doesnot exist
Post by: KAKAN on May 11, 2016, 05:40 PM
I already posted the correct answer, let me quote it again:
Quote from: KAKAN on May 11, 2016, 01:59 AM
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!
}
@Coolkid please, if you can understand English, then you can understand my code too.
Title: Re: .tostring doesnot exist
Post by: Cool on May 11, 2016, 06:20 PM
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