Is there an more efficient way to do this?
#1

PHP код:
DestroyObject(ResprayHangar[1]);
    
DestroyObject(ResprayHangar[2]);
    
DestroyObject(ResprayHangar[3]); 
^^ title says it all

PS: i am hoping for something like loop through out the array and destroy the objects?
PPS:
PHP код:
//global variables
new ResprayHangar[3]; 
Reply
#2

Код:
DestroyHangar()
{
	for(new i=0; i < sizeof ResprayHangar; i++) // loop through all indexes of respray hangar
	{
		if(IsValidObject(ResprayHangar[i])) // check if the object was created...maybe not all variable indexes contain object id's
		{
			DestroyObject(ResprayHangar[i]); // destroy the object
		}
	}	
}
Reply
#3

Quote:
Originally Posted by lolumadd_
Посмотреть сообщение
Код:
DestroyHangar()
{
	for(new i=0; i < sizeof ResprayHangar; i++) // loop through all indexes of respray hangar
	{
		if(IsValidObject(ResprayHangar[i])) // check if the object was created...maybe not all variable indexes contain object id's
		{
			DestroyObject(ResprayHangar[i]); // destroy the object
		}
	}	
}
"more efficient way to do this"

Laying it out directly is faster than a loop.

pawn Код:
DestroyObject(ResprayHangar[1]);
DestroyObject(ResprayHangar[2]);
DestroyObject(ResprayHangar[3]);
Reply
#4

ok thanks,
Reply
#5

Code functionality is more important than saving 1 nano second of processing speed.
Reply
#6

PHP код:
 if(checkpointid == CP[1] || CP[2] || CP[3] || CP[4]) 
So this is the "efficient" way to do this?
Reply
#7

Quote:
Originally Posted by xTURBOx
Посмотреть сообщение
PHP код:
 if(checkpointid == CP[1] || CP[2] || CP[3] || CP[4]) 
So this is the "efficient" way to do this?
Well, that's not the right syntax for an if statement with multiple "or" operators. Here are your options:

Код:
if(checkpointid == CP[1] || checkpointid == CP[2] || checkpointid == CP[3] || checkpointid == CP[4])
or

Код:
for(new i=0; i <= 4; i++)
{
	if(checkpointid == CP[i])
	{
		// do code for entering CP
		break; // break out of the loop
	}
}
Honestly, at your level of experience, I wouldn't worry too much about efficiency. There are many ways you could optimize your code in these situations but it probably wouldn't be much use to you. Rather, just learn how to get stuff functioning.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)