On 23 September 2011 19:50, Romain 'Maz' BILLOIR wrote:
I agree Colin, i can't use count...
and i can't use ant's id because every ants of every players got a
unique id, so, this may be possible:
ant 1, id = 1
ant 2, id = 2
ant 3, id = 5
ant 1, id = 3
ant 2, id = 4
ant 3, id = 6
ant 4, id = 7.
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:
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
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to email@example.com.
To unsubscribe from this group, send email to firstname.lastname@example.org.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.