Liberty Unleashed

Scripting => Script Help => Topic started by: Shadow. on July 02, 2012, 05:24:15 pm

Title: Error.. error.. error..
Post by: Shadow. on July 02, 2012, 05:24:15 pm
So, I have been thinking about this system that loads up previous player position from SQLite database, and sets you there, but I encounter an error.

Code: [Select]
function PrecachePosition(player)
{
player.Skin = sqlite_column_data(sqlite_query(database, "SELECT Skin FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
/* local x = sqlite_column_data(sqlite_query(database, "SELECT * FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),1);
local y = sqlite_column_data(sqlite_query(database, "SELECT * FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),2);
local z = sqlite_column_data(sqlite_query(database, "SELECT * FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),3);*/
local wep = sqlite_column_data(sqlite_query(database, "SELECT Wep FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
local ammo = sqlite_column_data(sqlite_query(database, "SELECT Ammo FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
player.SetWeapon( wep, ammo );
player.Frozen = false;
player.Pos = Vector( sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0) );
}



1.YES the data exists
2.YES the data is in FLOAT format
3.YES the data is valid
4.YES the data is in NUMERIC.NUMERIC format ( FLOAT )
5.YES the data is saved at onPlayerPart(player,partreason)
6.YES I tried to get the exact data and put '.tofloat()' after it
7.The line with the error is surprisingly
Code: [Select]
player.Pos = Vector( sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0) );


Yes I also tried this code
Code: [Select]
local x = sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
local y = sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
local z = sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
player.Pos = Vector( x.tofloat(), y.tofloat(), z.tofloat() );



also, when I make a class and default all the datas to null, then try to set them to 1, I receive a '' trying to set 'null ''



DO NOT COPY THIS CODE PLEASE
Title: Re: Error.. error.. error..
Post by: Knucis on July 02, 2012, 06:10:20 pm
DO NOT COPY THIS CODE, NEITHER THE IDEA
Sorry, but I had to post about this notice here. It's your fault if you are sharing your code, as long as they script the code themselves they are free to use it. And you are posting as that code is something new and revolutionary! lol, It has been present in every RP script afaik. (Including GameSparks  :P)
Title: Re: Error.. error.. error..
Post by: Shadow. on July 02, 2012, 06:17:04 pm
Thanks for the help, appreciated (NOT)
Title: Re: Error.. error.. error..
Post by: Shadow. on July 02, 2012, 10:11:06 pm
Look at the code and the pic

Quote
      local x = sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
      local y = sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
      local z = sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0);
      //local hp = sqlite_column_data(sqlite_query(database, "SELECT Health FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' "),0);
      //local ar = sqlite_column_data(sqlite_query(database, "SELECT Armour FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' "),0);
      //player.Health = hp.tointeger();
      //player.Armour = ar.tointeger();
      print( "Vector(" + x + "," + y + "," + z + ");" );
      player.Pos = Vector( x, y, z );


(http://i.imgur.com/apYCs.jpg)
Title: Re: Error.. error.. error..
Post by: VRocker on July 03, 2012, 12:45:30 pm
Just looked this up in the lu code, seems the error message is misleading because somebody forgot to throw a return afer an if.
It should say that the type passed to it is not a vector (which once again, makes no sense). Try loading the vector into a local, printing that then setting it. See what happens
Title: Re: Error.. error.. error..
Post by: Thijn on July 03, 2012, 01:59:37 pm
Also, Your usage of sqlite is the worst I've ever seen. Querying the database for every x,y,z is as bad as it can get...
Just query once, and get all the data you need from it...
Title: Re: Error.. error.. error..
Post by: Shadow. on July 03, 2012, 04:19:00 pm
Also, Your usage of sqlite is the worst I've ever seen. Querying the database for every x,y,z is as bad as it can get...
Just query once, and get all the data you need from it...
@ Thijn: Hey mr obvious, it is not. It's the SINGLE query that is supposed to return a float, and there is not a point to put it in a class, because ( obvious ) I use it just once.

passwords, admin level, LCPD Sub-divisions level & other things are obviously stored in a class.

But, of course you just come on and spit it, no point to actually ask.

@VRocker: tried, same thing
@VetalYA: tried, same thing

Thanks for the help, I will try few tweaks to see if I can do it.
Title: Re: Error.. error.. error..
Post by: stormeus on July 03, 2012, 05:59:29 pm
@ Thijn: Hey mr obvious, it is not. It's the SINGLE query that is supposed to return a float, and there is not a point to put it in a class, because ( obvious ) I use it just once.

passwords, admin level, LCPD Sub-divisions level & other things are obviously stored in a class.

It's still pretty bad when you can just put it all in one query like so:
Code: [Select]
local q = sqlite_query( database, "SELECT X, Y, Z, Skin, Wep, Ammo FROM LASTLOGIN WHERE Name='" + player.Name.toupper() + "' LIMIT 1" );

// x - Column 0
// y - Column 1
// z - Column 2
// etc.

Performing so many queries that could be done in one query could be detrimental to performance down the road. Not only that, but I'll never understand what the hell this is:

Code: [Select]
player.Pos = Vector( sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0) );

When you could've simply done:
Code: [Select]
local q = sqlite_query( database, "SELECT X, Y, Z FROM LASTLOGIN WHERE Name = '" + player.Name.toupper() + "' LIMIT 1" );

local x = sqlite_column_data( q, 0 ).tofloat();
local y = sqlite_column_data( q, 1 ).tofloat();
local z = sqlite_column_data( q, 2 ).tofloat();

Anyways, if you're still having problems, simply try this code:
Code: [Select]
player.Pos = Vector( 0.0, 0.0, 0.0 );

And see if it still complains about it not being a vector. If that one line works, then I'm going to guess that your problem is that you're performing too many goddamn operations on a single Vector constructor. In that case, try the code further above that deals with the database.
Title: Re: Error.. error.. error..
Post by: Shadow. on July 03, 2012, 06:34:40 pm
Same thing for ^^^ code.
Title: Re: Error.. error.. error..
Post by: stormeus on July 03, 2012, 06:35:51 pm
Same thing for ^^^ code.

Code: [Select]
print( typeof( player ) );
print( typeof( player.Pos ) );
Title: Re: Error.. error.. error..
Post by: Shadow. on July 03, 2012, 06:38:58 pm
1st : print( typeof( player ) ); = Player
2nd : print( typeof( player.Pos ) ); = string

EDIT 1st: if I /exec the 2nd, it returns Vector. lol...
EDIT 2nd: I printed player.Pos at onplayerspawn, it prints " Pos " LOL
Title: Re: Error.. error.. error..
Post by: stormeus on July 03, 2012, 06:48:00 pm
print( typeof( player.Pos ) ); = string

In that case, try print( player.Pos ), because that just doesn't look right.
Title: Re: Error.. error.. error..
Post by: LisKa on July 03, 2012, 07:59:42 pm
Player.Pos = string.   Why do you even use "type of" if it's already working with the simple one!...? And then arguing about that!
Title: Re: Error.. error.. error..
Post by: Shadow. on July 03, 2012, 08:49:07 pm

Player.Pos = string.   Why do you even use "type of" if it's already working with the simple one!...? And then arguing about that!
I wonder if you ever know what you are talking  ::)


Also, I solved it. NVM, put it on top of the script then changed 30 queries into 10 :p
Title: Re: Error.. error.. error..
Post by: VetalYA on July 03, 2012, 09:09:06 pm
Also, I solved it
Can you write, how ?
Title: Re: Error.. error.. error..
Post by: Shadow. on July 04, 2012, 09:30:56 am
Well simple, I moved the code by the beginning of the callback and changed all

Code: [Select]
sqlite_column_data(sqlite_query(database,"SELECT BLAH FROM LAG WHERE NAME='"+player.Name.toupper()"' "),0);
sqlite_column_data(sqlite_query(database,"SELECT BLAH1 FROM LAG WHERE NAME='"+player.Name.toupper()"' "),0);
sqlite_column_data(sqlite_query(database,"SELECT BLAH2 FROM LAG WHERE NAME='"+player.Name.toupper()"' "),0);

to

Code: [Select]
local q = sqlite_query(database,SELECT BLAH, BLAH1, BLAH2 FROM LAG WHERE NAME='"+player.Name.toupper()+"' LIMIT 1");

local blah1 = sqlite_column_data( q, 0 );
local blah2 = sqlite_column_data( q, 1 );
local blah3 = sqlite_column_data( q, 2 );

:)