Author Topic: Get Pickup pos and spawn from db  (Read 1470 times)

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Get Pickup pos and spawn from db
« on: December 28, 2013, 10:59:43 pm »
Hi,

I have a problem getting the position and spawn the pickups for the properties. When the server call the function, the pickups in the server doesn't spawn. It does not give me any errors.

Here the function:

Code: [Select]
function LoadProps()
{
if ( CountProps() != 0 )
{
    local q = sqlite_query( db, "SELECT * FROM Properties WHERE ID='%'" ), pos;
    while ( sqlite_column_data( q, 0 ) )
    {
local coords = sqlite_column_data( q, 5 );

CreatePickup( 1361, Vector( GetTok( coords, " ", 1 ).tofloat(), GetTok( coords, " ", 2 ).tofloat(), GetTok( coords, " ", 3 ).tofloat() ) );
sqlite_next_row( q );
    }
sqlite_free( q );
}
}

I'm newbie in SQLite...
« Last Edit: December 29, 2013, 08:55:25 pm by Slayer »
Westwood Studios

The best studios company in strategy videogames.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Get Pickup pos and spawn from db
« Reply #1 on: December 28, 2013, 11:46:43 pm »
Without an error, it's harder to determine the source.

However, I think your query might not be right. The WHERE clause shouldn't exist if you are trying to pull all the records from a table. Also, you may need to include field names in your query to help manage what is selected. Just use something like this:
Code: [Select]
"SELECT ID,Coords FROM Properties"
And column data 0 will be your ID, and column data 1 will be your coordinates.

EDIT: I messed up the bold thing in my original post.
« Last Edit: December 29, 2013, 03:27:59 pm by Vortrex »

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Re: Get Pickup pos and spawn from db
« Reply #2 on: December 29, 2013, 11:42:20 am »
Without an error, it's harder to determine the source.

However, I think your query might not be right. The WHERE clause shouldn't exist if you are trying to pull all the records from a table. Also, you may need to include field names in your query to help manage what is selected. Just use something like this:
Code: [Select]
"SELECT ID,Coords FROM Properties"
And column data 0 will be your ID, and column data 1 will be your coordinates.

The problem is not in this function, is in "CountProps"...
When the server call this function (CountProps), fails,I have seen with "print", the server does not come over there

Code: [Select]
function CountProps()
{
    local a = 0, q = sqlite_query( db, "SELECT ID FROM Properties" );
while ( sqlite_column_data( q, 0 ) )
{
a++;
sqlite_next_row( q );
}
return a; 
sqlite_free( q );
}

ADMIN EDIT: Stop insulting!
USER EDIT: Insulting what ? LOL
« Last Edit: December 29, 2013, 08:40:23 pm by Slayer »
Westwood Studios

The best studios company in strategy videogames.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Get Pickup pos and spawn from db
« Reply #3 on: December 29, 2013, 03:31:51 pm »
If the problem is in a different function, why didn't you post that function in the first place?

Also, try this query instead:
Code: [Select]
SELECT count(*) FROM Properties
That should give you a number of rows. Use this data like any other query, like so:
Code: [Select]
sqlite_column_data( q , 0 )

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Re: Get Pickup pos and spawn from db
« Reply #4 on: December 29, 2013, 08:39:17 pm »


-- Topic closed --

Thanks to Vortrex to help me.
Westwood Studios

The best studios company in strategy videogames.

 

© Liberty Unleashed Team.