Optimize my function
#1

Hi!

How can I optimize this function with a loop ?

thanks

Код HTML:
Function(playerid)
{
	if(PlayerInfo[playerid][house1] == 40)
	{
		PlayerInfo[playerid][house1] = 0;
	}
	else if(PlayerInfo[playerid][house2] == 40){
		PlayerInfo[playerid][house2] = 0;
	}
	else if(PlayerInfo[playerid][house3] == 40){
		PlayerInfo[playerid][house3] = 0;
	}
	else if(PlayerInfo[playerid][house4] == 40){
		PlayerInfo[playerid][house4] = 0;
	}
	else if(PlayerInfo[playerid][house5] == 40){
		PlayerInfo[playerid][house5] = 0;
	}
	else if(PlayerInfo[playerid][house6] == 40){
		PlayerInfo[playerid][house6] = 0;
	}
	else if(PlayerInfo[playerid][house7] == 40){
		PlayerInfo[playerid][house7] = 0;
	}
	else if(PlayerInfo[playerid][house8] == 40){
		PlayerInfo[playerid][house8] = 0;
	}
	return 1;
}
Reply
#2

in you enum PlayerInfo[playerid][house1] you have the one var for each house? as: house1, house2, house3? or house = all house ids?

can you post here the PlayerInfo enum?
Reply
#3

You fucked yourself up with your data structures so everywhere in your code will need to be updated now to fix this. What you should have is something like this.

new PlayerInfo[playerid][MAX_PLAYER_HOUSES][HouseENUM]

It would be best though to separate your house system from your player interface then you could just save a list of references for each house a player owns which will reduce resources requires. I would just using mysql/sqlite and just save the primary integer keys.
Reply
#4

Quote:
Originally Posted by Pottus
Посмотреть сообщение
You fucked yourself up with your data structures so everywhere in your code will need to be updated now to fix this. What you should have is something like this.

new PlayerInfo[playerid][MAX_PLAYER_HOUSES][HouseENUM]
yeah, i don't know what is that function purposes...

[house1] == 40?
Reply
#5

If "house1, house2, house3, etc." is a factor or a enumerator and the first factor starts at index 0 (modify the loop's initial and final value if it does not start at index 0), you can do:
pawn Код:
for(new i = 0; i < 8; i ++)
{
    if(PlayerInfo[playerid][nameOfEnumerator:i] == 40)
    {
        PlayerInfo[playerid][nameOfEnumerator:i] = 0;
    }
}
Please note that you must change "nameOfEnumerator" to the correspondent name of your enumerator.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)