SA-MP Forums Archive
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(23322330.53412392.489511.74540.00000.00000.0000);
obTown[1] = CreateDynamicObject(81682293.59832370.78958.16950.00000.000016.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 0sizeof(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.