DestroyDynamicObject destroying the wrong object - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: DestroyDynamicObject destroying the wrong object (
/showthread.php?tid=653473)
DestroyDynamicObject destroying the wrong object -
Amads - 05.05.2018
And I have no idea why.
PHP Code:
// top of the gamemode
new obTown[300];
new obTemp;
// GameModeInit
obTown[0] = CreateDynamicObject(2332, 2330.5341, 2392.4895, 11.7454, 0.0000, 0.0000, 0.0000);
obTown[1] = CreateDynamicObject(8168, 2293.5983, 2370.7895, 8.1695, 0.0000, 0.0000, 16.6998); // and so on...
// somewhere else in the code
if(IsValidDynamicObject(obTemp)) DestroyDynamicObject(obTemp); // HERE IS THE PROBLEM
Simple enough, should work, right?
Well, for god knows what reason the last line deletes
obTown[0] object, even thought I've added
IsValidDynamicObject(obTemp), and obTemp wasn't created yet. So why on earth does the last code delete
obTown[0]?
Primo, the code after IsValidDynamicObject(obTemp) should not execute. Secundo, it should not even a random object when it cannot find obTemp.
Am I missing something here?
Re: DestroyDynamicObject destroying the wrong object -
SeanDenZYR - 06.05.2018
Try this, you have defined "obTemp" only, so, it will delete the first value (which is 0).
try adding a loop to it by doing this:
PHP Code:
for(new i = 0; i < sizeof(obTemp), i++)
{
if(IsValidDynamicObject(obTemp[i])) DestroyDynamicObject(obTemp[i]);
}
Re: DestroyDynamicObject destroying the wrong object -
Amads - 06.05.2018
But obTemp is not an array, it is a single object.