Finding unused indexid
#1

um i still i don't know how do you find unused index id, for example
PHP Code:
//under createobject command
        
objects++;
        
objectsid[objects]=objectid;
        new 
Float:XFloat:YFloat:Zstr[128];
        
GetPlayerPos(playeridXYZ);
        
SpawnedObject[objects] = CreateObject(//etc etc 
i take 'objects' as the objects like indexid to select it later on, what if i created 10 objects, i deleted one with object id 4, how can i find it
if you didnt get what i mean then another example
i created 5 numbers, 1 2 3 4 5 in a sequence, i deleted 3 from the sequence now how will i be able to find it
Reply
#2

pawn Code:
new freeObjectId;
for(new i=0; i<MAX_OBJECTS; i++) {
    if(!IsValidObject(SpawnedObject[i])) {
        freeObjectId = i;
        break;
    }
}

SpawnedObject[i] = CreateObject();
Should essentially check for the first entry in SpawnedObject array that isn't assigned a valid object, then return that as freeObjectId.

I don't know if it works and I'm sure there's a more efficient way of doing it. Haven't done this in a long time.
Reply
#3

Thanks and also i'll try that out, i wanted to ask another thing, how can i run a loop like backwards like i tried using
PHP Code:
for(new =40i>0i--) 
but i read somewhere that this wont work as condition is always true, i need something like 40 to 0

EDIT: My mistake while writing, (i was supposed to write 40) i tried using it but it doesn't seem to work
Reply
#4

Quote:
Originally Posted by SaiyanZ
View Post
Thanks and also i'll try that out, i wanted to ask another thing, how can i run a loop like backwards like i tried using
PHP Code:
for(new =0i>0i--) 
but i read somewhere that this wont work as condition is always true, i need something like 40 to 0
Almost had it:
pawn Code:
for(new i = 40; i>0; i--)
EDIT: It should work. Condition is true when i is > 0. if i becomes 0 the condition is no longer true and the loop stops.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)