Or you could just make sure all of the bots on your team have the same name plus a number... like have Bot1, Bot2, etc. You could know that Bot1 was the leader, but its name would be the same... it's a question of simplicity over choosing a name... --Bayen, on returning to the wiki!! |
Or you could just make sure all of the bots on your team have the same name plus a number... like have Bot1, Bot2, etc. You could know that Bot1 was the leader, but its name would be the same... it's a question of simplicity over choosing a name... --Bayen, on returning to the wiki!! * Welcome back! --Starrynte |
The following function does it:
static public int getBotNumber(String name) { String n = "0"; int low = name.indexOf("(")+1; int hi = name.lastIndexOf(")"); if (low >= 0 && hi >=0) { n = name.substring(low, hi); } return Integer.parseInt(n); }Note that I have not tested it when there is more than one class of bots in a team. -- Albert
So how do you deal with a situation like this?
if(getEnergy()>199.0){ //220 if leader is a droid, 200 otherwise. String[] teammates = getTeammates(); Vector v = new Vector(); v.add(getName()); for(int i = 0; i < teammates.length; i++){ v.add(teammates[i]); } teammates = (String[]) v.toArray(); try{ broadcastMessage(teammates); }catch(Exception e){} }
Then just have all bots store the String[] message and do lookups in that array to get the ID of a bot. (Bot ID = position in array)
Or you could just make sure all of the bots on your team have the same name plus a number... like have Bot1, Bot2, etc. You could know that Bot1 was the leader, but its name would be the same... it's a question of simplicity over choosing a name... --Bayen, on returning to the wiki!!