Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Xmair on Sep 03, 2015, 11:32 AM

Title: [Error].ToString doesn't exists
Post by: Xmair on Sep 03, 2015, 11:32 AM
Line 2565
local Pos = GetSQLColumnData( q, 5 ).tostring();
The function LoadHouse()
function LoadHouse()

        local a = 1, HCount = HouseCount();
        while ( a <= HCount )
        {
                local q = QuerySQL( db, "SELECT Pos FROM Houses WHERE ID=" + a ); 
                local Pos = GetSQLColumnData( q, 5 ).tostring();
                CreatePickup( 406, Vector( GetTok( Pos, " ", 1 ).tofloat(), GetTok( Pos, " ", 2 ).tofloat(), GetTok( Pos, " ", 3 ).tofloat() ) );
                if ( a == HCount )
FreeSQLQuery( q );
                a ++;
        }
print( "Loaded: " + HCount + " houses." );
}
Table
    QuerySQL( db, "CREATE TABLE IF NOT EXISTS Houses ( ID NUMERIC, Name TEXT, Price NUMERIC, Owner TEXT, Sharer TEXT, Pos TEXT )" );
HouseCount function
function HouseCount()
{
        local a = 0, q = QuerySQL( db, "SELECT * FROM Houses" );
        while ( GetSQLColumnData( q, 0 ) )
        {
                a ++;
                GetSQLNextRow( q );
        }
        return a; 
FreeSQLQuery( q );
}
Error
AN ERROR HAS OCCURED [the index 'tostring' does not exist]

CALLSTACK
*FUNCTION [LoadHouse()] Scripts/Functions.nut line [2565]

LOCALS
[q] NULL
[HCount] 1
[a] 1
[this] TABLE
Title: Re: [Error].ToString doesn't exists
Post by: KAKAN on Sep 03, 2015, 12:07 PM
Why don't you use .tointeger() ??
Title: Re: [Error].ToString doesn't exists
Post by: . on Sep 03, 2015, 12:12 PM
Code:
function dummy()
{
    return null;
}

print(dummy().tointeger());

Output:
AN ERROR HAS OCCURED [the index 'tointeger' does not exist]
Do you see the issue now ? Try this way to see if I was right.

Code:
function dummy()
{
    return null;
}

print(dummy() + "");

Output:
[SCRIPT]  (null : 0x00000000)
Title: Re: [Error].ToString doesn't exists
Post by: EK.IceFlake on Sep 03, 2015, 12:19 PM
tostring doesn't exist at all.
function tostring(str)
{
    return str+"";
}
Title: Re: [Error].ToString doesn't exists
Post by: DizzasTeR on Sep 03, 2015, 12:54 PM
Quote from: NE.CrystalBlue on Sep 03, 2015, 12:19 PMtostring doesn't exist at all.
function tostring(str)
{
    return str+"";
}

What stupidity is this if I may ask.
Title: Re: [Error].ToString doesn't exists
Post by: EK.IceFlake on Sep 03, 2015, 01:17 PM
Quote from: Doom_Killer on Sep 03, 2015, 12:54 PM
Quote from: NE.CrystalBlue on Sep 03, 2015, 12:19 PMtostring doesn't exist at all.
function tostring(str)
{
    return str+"";
}

What stupidity is this if I may ask.
Well I once dealt with integers and they didn't have .tostring. I assume same with floats
Title: Re: [Error].ToString doesn't exists
Post by: KAKAN on Sep 03, 2015, 01:20 PM
.tostring() exists, I have used it in my wep command
Title: Re: [Error].ToString doesn't exists
Post by: . on Sep 03, 2015, 01:23 PM
Integers/Floats/Booleans/Strings they all have tointeger(), tofloat(). tostring() The remaining types don't have it with the exception of custom objects which can manually implement it.

But I'm guessing that no one gave a f* to that post I made detailing the fact that null doesn't have it and is one of the return types of GetSQLColumnData() once it fails to retrieve the specified column data.

And as a fun story this is my 777'th post :D
Title: Re: [Error].ToString doesn't exists
Post by: rObInX on Sep 03, 2015, 02:01 PM
If you gave a look at S.L.C's post.
But, none did.

Here is the code coz no one understand words, only codes....

local Pos;
if ( GetSQLColumnData( q, 5 ) )
{
    Pos = GetSQLColumnData( q, 5 ).tostring();
    //rest of your stuf.
}
else No house
Title: Re: [Error].ToString doesn't exists
Post by: Kratos_ on Sep 03, 2015, 02:50 PM

GetSQLColumnData operates over the value returned by query & not the actual table in the database .

local q = QuerySQL( db, "SELECT Pos FROM Houses WHERE ID=" + a );
local Pos = GetSQLColumnData( q, 5 ).tostring();

Your query is selecting just one column "Pos" from the actual table . But , you're attempting to get 6th column which the query never returns . To fix this , simply write this :-

local q = QuerySQL( db, "SELECT Pos FROM Houses WHERE ID=" + a );
// First & only column which is selected through query
local Pos = GetSQLColumnData( q, 0 ).tostring();

OffTopic : You shouldn't select entire table just for counting no of rows .
Title: Re: [Error].ToString doesn't exists
Post by: Xmair on Sep 03, 2015, 03:15 PM
Thanks to everyone, It's fixed and I learned something more.
Anyway, Another one.
onPlayerCommand Error : Cannot convert the stringelse if ( cmd == "addhouse" )
{
if ( !text ) MessagePlayer("/addhouse <Pickup ID> <Housename> <HousePrice>",player)
else
{
local housepickup = GetTok( text, " ", 1 ).tointeger();
local housename = GetTok( text, " ", 2 ).tointeger();
local houseprice = GetTok( text, " ", 3 ).tointeger();
  CreatePickup( 406, player.Pos )
QuerySQL( db, "INSERT INTO Houses ( ID, Name, Price, Owner, Sharer, Pos ) VALUES ( '"+housepickup+"', '"+housename+"', 'Vice-City', 'None', '"+player.Pos+"')");
MessagePlayer("Created house, ID :- "+housepickup+". Name :- "+housename+". Price :- "+houseprice+"!",player)
}
}
Title: Re: [Error].ToString doesn't exists
Post by: . on Sep 03, 2015, 03:21 PM
Same story:
local my_str = "xyz";

print( my_str.tointeger() );

Output:
AN ERROR HAS OCCURED [cannot convert the string]
Can you convert "xyz" to a number?
Title: Re: [Error].ToString doesn't exists
Post by: Xmair on Sep 03, 2015, 03:37 PM
Hahaha :P @S.L.C Fixed XD