SA-MP Forums Optimize my function
 User Name Remember Me? Password
 New Account Members List Search Today's Posts Mark Forums Read

 Thread Tools Display Modes
 19/05/2017, 03:54 PM #1 pelican1 Little Clucker   Join Date: Jan 2017 Posts: 24 Reputation: 0 Optimize my function Hi! How can I optimize this function with a loop ? thanks HTML Code: 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; }
 19/05/2017, 04:00 PM #2 rolex Big Clucker     Join Date: Nov 2008 Posts: 127 Reputation: 15 Re: Optimize my function 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?
 19/05/2017, 04:00 PM #3 Pottus Godfather     Join Date: Jun 2012 Posts: 5,279 Reputation: 1141 Re: Optimize my function 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.
19/05/2017, 04:05 PM   #4
rolex
Big Clucker

Join Date: Nov 2008
Posts: 127
Reputation: 15
Re: Optimize my function

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?

 19/05/2017, 05:32 PM #5 CheezIt Big Clucker     Join Date: Apr 2017 Posts: 186 Reputation: 15 Re: Optimize my function 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: Code: 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. __________________ I like to share footage of things I find interesting, cool, funny and anything in between!

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post StreK Scripting Help 6 14/05/2016 12:25 PM Magic_Time Scripting Help 1 28/08/2014 08:37 PM sim_sima Scripting Help 5 15/12/2013 07:20 PM Tomejus Help Archive 0 22/02/2011 02:12 PM

All times are GMT. The time now is 11:12 PM.

 -- (EN) English -- (ES) Espaņol -- (RU) Русски Contact Us - SA-MP - Archive - Top