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
Why don't you use .tointeger() ??
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)
tostring doesn't exist at all.
function tostring(str)
{
return str+"";
}
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.
Quote from: Doom_Killer on Sep 03, 2015, 12:54 PMQuote 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
.tostring() exists, I have used it in my wep command
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
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
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 .
Thanks to everyone, It's fixed and I learned something more.
Anyway, Another one.
onPlayerCommand Error : Cannot convert the string
else 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)
}
}
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?
Hahaha :P
@S.L.C Fixed XD