function PropCount()
{
Line 2439 local a = 0, q = QuerySQL( db, "SELECT * FROM Props" );
while ( GetSQLColumnData( q, 0 ) )
{
a ++;
GetSQLNextRow( q );
}
return a;
FreeSQLQuery( q );
}
function LoadProps()
{
Line 2692 local a = 1, PCount = PropCount();
while ( a <= PCount )
{
local q = QuerySQL( db, "SELECT PType, Pos FROM Props WHERE ID=" + a );
local Pos = GetSQLColumnData( q, 1 ).tostring();
CreatePickup( GetSQLColumnData( q, 0 ).tointeger(), Vector( GetTok( Pos, " ", 1 ).tofloat(), GetTok( Pos, " ", 2 ).tofloat(), GetTok( Pos, " ", 3 ).tofloat() ) );
if ( a == PCount )
FreeSQLQuery( q );
a ++;
}
print( "Loaded: " + PCount + " props." );
}
Line 239 LoadProps();
Createtable : QuerySQL( db, "CREATE TABLE IF NOT EXISTS Props ( ID NUMERIC, Name TEXT, Price NUMERIC, Owner TEXT, Sharer TEXT, Spawnstatus TEXT, Pos TEXT, PType NUMERIC )" );
Error.
AN ERROR HAS OCCURED [parameter 1 has an invalid type 'null' ; expected: 'userdata']
CALLSTACK
*FUNCTION [PropCount()] Scripts/Functions.nut line [2439]
*FUNCTION [LoadProps()] Scripts/Functions.nut line [2692]
*FUNCTION [onScriptLoad()] Scripts/UDM-SQ.nut line [239]
LOCALS
[a] 0
[this] TABLE
[a] 1
[this] TABLE
[this] TABLE
[0;30m[WARNING][0;37m onScriptLoad failed to execute -- check the console for more details.
rofl what.
Let's say you have 20 properties.
You first execute 1 query to get all properties. Then loop through them and keeping a counter to get the amount of properties.
Then you have the number, 20. Then you're going to make another loop that's going to make 20 queries to get the Pos etc. from each property.
This could be done with just 1 query. Which you already made.
function LoadProps()
{
local q = QuerySQL( db, "SELECT * FROM Props" ), a = 0;
while ( GetSQLColumnData( q, 0 ) )
{
local Pos = GetSQLColumnData( q, 1 ).tostring();
CreatePickup( GetSQLColumnData( q, 0 ).tointeger(), Vector( GetTok( Pos, " ", 1 ).tofloat(), GetTok( Pos, " ", 2 ).tofloat(), GetTok( Pos, " ", 3 ).tofloat() ) );
GetSQLNextRow( q );
a++;
}
FreeSQLQuery( q );
print( "Loaded: " + a + " props." );
}
The error you got probably means your "db" variable isn't defined globally.
Thanks, fixed.