This topic was marked solved by its starter, on February 20th, 2017, 07:18 PM

Cool

  • Hero Member
  • Posts: 719
load props error
« on February 20th, 2017, 07:11 AM »
its working fine but when i create 1 prop and then restart after restarting its start giving me error of PX Does not exists
Code: [Select]
function LoadProps()
{
 local q = mysql_query( sqliteDB, "SELECT * FROM Properties" ), i = 0;
  if( mysql_num_rows( q ) == 1 ) {
local result = mysql_fetch_assoc( q );
  PX = result[ "PX" ];
  PY = result[ "PY" ];
  PZ = result[ "PZ" ];
  CreatePickup( 407, Vector( PX.tofloat(), PY.tofloat(), PZ.tofloat() ) );
mysql_free_result(q);
  i++;
 
 }
  print( "Props loaded - " + i );
 
}

redax

  • Newbie
  • Posts: 13
Re: load props error
« Reply #1, on February 20th, 2017, 01:26 PM »
That means this line didnt work:

Code: [Select]
PX = result[ "PX" ];
idk much about mysql but maybe your /addprop cmd did not save the prop positions in the db,thats all i can say.

Cool

  • Hero Member
  • Posts: 719
Re: load props error
« Reply #2, on February 20th, 2017, 01:38 PM »
Quote from redax on February 20th, 2017, 01:26 PM
That means this line didnt work:

Code: [Select]
PX = result[ "PX" ];
idk much about mysql but maybe your /addprop cmd did not save the prop positions in the db,thats all i can say.
Nope its save pos i checked db

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,107
Re: load props error
« Reply #3, on February 20th, 2017, 01:54 PM »
You're creating the var "i" for loop and also you're adding it with "i++" but I don't see a loop

Cool

  • Hero Member
  • Posts: 719
Re: load props error
« Reply #4, on February 20th, 2017, 02:31 PM »
Quote from Doom_Kill3R on February 20th, 2017, 01:54 PM
You're creating the var "i" for loop and also you're adding it with "i++" but I don't see a loop
Doom then why its not give me error with correct details @Developers Should Take a new Developer if they cant handle vcmp alone because all plugins are not giving correct error details and there are also bugs in game which is not ffixed  they have a person who can take that responsibility
He also did many works ffor vcmp such as http://forum.vc-mp.org/?board=40.0

KAKAN

  • Wiki Contributor
  • Posts: 3,346
Re: load props error
« Reply #5, on February 20th, 2017, 04:42 PM »
on-topic: use a while loop.
something like:-
Code: [Select]
local result;
while( result = mysql_fetch_assoc( q ) ){ /*your code here*/ }

off-topic:
Quote from happymint2 on February 20th, 2017, 02:31 PM
Quote from Doom_Kill3R on February 20th, 2017, 01:54 PM
You're creating the var "i" for loop and also you're adding it with "i++" but I don't see a loop
Doom then why its not give me error with correct details @Developers Should Take a new Developer if they cant handle vcmp alone because all plugins are not giving correct error details and there are also bugs in game which is not ffixed  they have a person who can take that responsibility
He also did many works ffor vcmp such as http://forum.vc-mp.org/?board=40.0
ROFL XDDDDDDD I can't stop laughing at it lol
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,804
Re: load props error
« Reply #6, on February 20th, 2017, 05:42 PM »Last edited on February 20th, 2017, 05:45 PM
The problem here is that you forgot to add `local` before the `PX` variable. So it's the variable that doesn't exist not the value in the row.

Code: [Select]
  PX = result[ "PX" ];
  PY = result[ "PY" ];
  PZ = result[ "PZ" ];

To this:
Code: [Select]
  local PX = result[ "PX" ];
  local PY = result[ "PY" ];
  local PZ = result[ "PZ" ];

If you want to automatically report errors from your SELECT queries. Then feel free to wrap the function into one that does:
Code: [Select]
function SafeSelect(db, str) {
    local result = mysql_query(db, str);
    // If the result is null, nothing was selected
    if (result == null)
        return null;
    // If the result is false, there was an error
    else if (result == false)
        throw format("MySQL Error (%d): %s", mysql_errno(db), mysql_error(db));
    // At this point something was selected and we have it
    else
        return result;
}

And you can probably write your code better by using a for loop and validating some things before using them:
Code: [Select]
function LoadProps() {
    // Use the SafeSelect wrapper so it can repport errors, if any
    local q = SafeSelect(sqliteDB, "SELECT * FROM `Properties`");
    // See if there were any rows in the `Properties` table
    if (q == null) {
        print("No props exist");
        // No point in going forward
        return;
    }
    local count = 0;
    // Use a for loop to iterate over the selected rows
    for (local row = mysql_fetch_assoc(q); row != null; row = mysql_fetch_assoc(q)) {
        // Grab the values from the current row
        local PX = row["PX"].tofloat()
            , PY = row["PY"].tofloat()
            , PZ = row["PZ"].tofloat();
        // Attempt to create the pickup with resulted values
        local pickup = CreatePickup(407, Vector(PX, PY, PZ));
        // Validate the pickup instance
        if (pickup == null)
            print("Failed to create pickup at: " + PX ", " + PY + ", " + PZ);
        else
            ++count;
    }
    // Finally, we can free the query
    mysql_free_result(q);
    // Whatever...
    print("Props loaded: " + count);
}
.

Cool

  • Hero Member
  • Posts: 719