Let's say that there are 10 tokens in initiative (0-9) and the current token is 3. I want to take another token at a different position and insert them before the current token.
Code: Select all
getInitiativePosition(token): position
// Returns the position of the token in the initiative, "" if not there
token - id of token in initiative
position - value of the position of the token (starts at 0)
moveInInitiative(old position, new position): complete
// removes token from old position and inserts at new position
old position - this is the current position of the token to be moved (see getInitiativePosition)
new position - this is the new position of token. All tokens with the same or greater position are moved
up in position up to the old position.
complete - 0 if move could not be done due to invalid position values, 1 if move takes place.
As a side note, putting a position greater than the max position puts it after the last position. So, a move from 3 to 10 (in a 0-9 array) will put new position at 9 and decrement 4-9 to 3-8.
I also think the sort function should include an ascending/descending option.