| Blockland Forums > Modification Help |
| UI Name Table for playertypes? [Solved] |
| << < (2/4) > >> |
| Port:
--- Quote from: Lugnut1206 on April 05, 2012, 11:38:49 PM --- --- End quote --- Why are you calling serverConnection.getCount() over and over, for example even potentially 50000 times on large servers? |
| Greek2me:
Ok, so this is the little function I created: --- Code: ---function SlayerClient_Support::getIDFromUiName(%uiName) { %count = serverConnection.getCount(); for(%i=0; %i < %count; %i++) { %obj = serverConnection.getObject(%i); if(%obj.uiName $= %uiName) return %obj; } return -1; } --- End code --- The only problem is that it's extremely inefficient, especially with larger brickcounts, etc. Right now my benchmarking script gives this an average benchmark score of 29. For my use I would need that score to be anywhere from 0 to 10. Any ideas on how to make this more efficient? |
| computermix:
I used this to get a simple list: --- Code: ---for(%i=0;%i<serverconnection.getCount();%i++) { %o=serverconnection.getobject(%i); if(%o.getClassName()$="playerData") { echo(%o.uiname); } } --- End code --- EDIT: aw shat you beat me EDIT2: I just tested this on glasses server, and it worked. Showed an neat list (it didn't take too long to loop through serverconnection, spat it out in less than a second) |
| Port:
--- Quote from: Greek2me on April 06, 2012, 12:00:36 AM --- --- End quote --- End the loop as soon as you see an object with a class name that does not end with "Data". While datablocks could be made on-the-go for the server, it is highly unlikely to happen and is a bad idea anyway. |
| Greek2me:
--- Quote from: Port on April 06, 2012, 12:04:43 AM ---End the loop as soon as you see an object with a class name that does not end with "Data". While datablocks could be made on-the-go for the server, it is highly unlikely to happen and is a bad idea anyway. --- End quote --- That's risky, since people can name their datablocks anything. Here's what I ended up doing: --- Code: ---function SlayerClient_Support::getIDFromUiName(%uiName) { %count = serverConnection.getCount(); for(%i=0; %i < %count; %i++) { %obj = serverConnection.getObject(%i); if(%obj.getClassName() $= "MissionArea") break; if(%obj.uiName $= %uiName) return %obj; } return -1; } --- End code --- This reduces the benchmark score to around a 7. Thanks for your help everyone! |
| Navigation |
| Message Index |
| Next page |
| Previous page |