Is there an more efficient way to do this?
#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


Messages In This Thread
Is there an more efficient way to do this? - by xTURBOx - 12.06.2016, 15:46
Re: Is there an more efficient way to do this? - by lolumadd_ - 12.06.2016, 15:58
Re: Is there an more efficient way to do this? - by SickAttack - 12.06.2016, 15:59
Re: Is there an more efficient way to do this? - by xTURBOx - 12.06.2016, 16:02
Re: Is there an more efficient way to do this? - by lolumadd_ - 12.06.2016, 16:04
Re: Is there an more efficient way to do this? - by xTURBOx - 12.06.2016, 16:15
Re: Is there an more efficient way to do this? - by lolumadd_ - 12.06.2016, 16:43

Forum Jump:


Users browsing this thread: 3 Guest(s)