Posts: 1,219
Threads: 51
Joined: Jul 2012
Instead of doing a for loop , looping thru all the houses you could just enter all the houses the player owns into his user file / databank , so the big loop is unneccessary
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
The only other way I can think of is after the player logins, execute the code from that function once to see if the player has any house and store the result to a variable (global per-player). When the player buys a house, increase by one and when he sells it, decrease by one.
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
Reducing the loop will give an advantage as well. Have a global variable and when the server starts and loads the houses, assign to the variable how many houses were loaded. Then on the loop, go until the variable and not the sizeof of House array. Don't forget then to increase/decrease depending on adding/deleting a house.
Posts: 1,167
Threads: 57
Joined: Jul 2010
Reputation:
0
I would store all houses which player owns at login in a new variable, and at the rest of the places, just loop through those variables not the whole houses.
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
It would reduce the times the loop goes if the size of House array is let's say 500 and you have only 400 houses created. If you mean by "constant number of houses" that your array "House" is full then yes, it does nothing (you didn't mention it though).
The best suggestion however would be to use SQL instead and all you need is a simple query.
Posts: 694
Threads: 2
Joined: Oct 2012
Reputation:
0
There are a couple of ways
A) Using SQL and then using queries
B) Using foreach and multi dimensional iterators.
C) Loading everything on start, keeping the data in an array for each player.
I recommend A or B or both.
Posts: 3,324
Threads: 96
Joined: Sep 2013
If it were me, I'd be doing this inside a SQL database. You can count the player's houses using "select * where owner is playername". That would be super quick and simple.