Why not just use the id of the ant?
If you need them to start from 1 for each player then when you make an
new ant look up the highest number for that player's ants and add one
to that.
Colin
The simple answer is it would be trivial to have ants have unique names use ant id.
THe simples i can see is to use player.ant.count (select + update )
do a count of ants for player before each batch creation
I thought of 4 other ways but this is the simplest.
Using count will not work. Suppose there were three, numbers 1, 2 and
3. Suppose number 2 is deleted leaving 1 and 3. If a new one were
created it would get 3 again if count were used. It is necessary to
find the current highest and increment that so the new one will be 4.
Colin
Your initial post did not say that there would be any problems with
the numbering above
>
> And the Colin's solution isn't good too, suppose:
> Player 1:
> ant 1, id = 1, name = 1
> ant 2, id = 2, name = 2
> ant 3, id = 3, name = 3
>
> Player2 subscribe and create 3ants:
> on the first ant's creation i just put the name to 1 and the twice
> follower just got the previously name+1, so:
> ant 1, id = 4, name = 1
> ant 2, id = 5, name = 2
> ant 3, id = 6, name = 3
>
> Player1 attacks Player2. The Player2's ant which has got the id = 6,
> name = 3 dies.
> Player2 creates a new ant the "highest number for that player's ants"
> will be the ant which has got the id = 5, name = 2 so the next name
> will be 3. Again.
Again, your initial post did not say that you must not use the same
number again. In that case you need a column in the players table
keeping the last used number for each player and use that to determine
the next ant number.
>
> Is there noway to create sequence from controller?
I don't understand what you mean. If the requirement is that each
player's ants must start from 1 and increment for each ant, and a
number must not be re-used if an ant is destroyed then the only way of
achieving this is to keep a record for each player of the last used
number, and there is no sensible place to store it other than in the
players record.
Colin
--
gplus.to/clanlaw
He asked for unique it is true
If you want todo this with posygresl - you may be bettrr off using psql and a trigger and a sequence and adking in the plsql forum.
AND then please post what you doo!!
On Sep 22, 2011 2:43 PM, "Romain 'Maz' BILLOIR" <bill...@gmail.com> wrote:
>