its working fine but when i create 1 prop and then restart after restarting its start giving me error of PX Does not exists
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 );
}
That means this line didnt work:
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.
Quote from: redax on Feb 20, 2017, 01:26 PMThat means this line didnt work:
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
You're creating the var "i" for loop and also you're adding it with "i++" but I don't see a loop
Quote from: Doom_Kill3R on Feb 20, 2017, 01:54 PMYou'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
on-topic: use a while loop.
something like:-
local result;
while( result = mysql_fetch_assoc( q ) ){ /*your code here*/ }
off-topic:
Quote from: happymint2 on Feb 20, 2017, 02:31 PMQuote from: Doom_Kill3R on Feb 20, 2017, 01:54 PMYou'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
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.
PX = result[ "PX" ];
PY = result[ "PY" ];
PZ = result[ "PZ" ];
To this:
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:
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:
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);
}
Thanks
@happymint for explaining