[FREQ 1.4] Move a token in Initiative

Developer discussion regarding MapTool 1.4

Moderators: dorpond, trevor, Azhrei

Forum rules
Posting now open to all registered forum users.
Post Reply
User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

[FREQ 1.4] Move a token in Initiative

Post by aliasmask »

I was trying to think of an easy way to move a token to a different position in the initiative panel and I don't see a method other than rewriting the entire initiative. I don't want to use sort because the move may not reflect the values. Can we get a function or two for that?

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. 
This is simulating essentially what can only be done manually in MapTool, dragging one token to another position in the panel.

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.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [FREQ 1.4] Move a token in Initiative

Post by aliasmask »

Very minor gripe.

Another thing I noticed about Wiki: getInitiativeList() is that the holding value returns false or true. It shows them not in quotes, but as boolean values. But if I try to use the raw value in an if statement, it doesn't recognize it as such. I can compare them as strings but that's an extra step. Can you just put 0 or 1.

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: [FREQ 1.4] Move a token in Initiative

Post by JamzTheMan »

I also believe there isn't an easy way to get a tokens init, I believe it either gets it's position IIRC? Anyhoo, the Initiative tool needs a lot of love but in the mean time a few functions could really help.

Do you want to make a wish list of function names with parameters to fill those gaps? Also, if I change the return value, it could also break existing campaigns couldn't it?
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [FREQ 1.4] Move a token in Initiative

Post by aliasmask »

One way to get positions based on token id is to extract the tokens array and check tokenId in each object in the array position, then note the position. You can also use the existing functions to change the current initiative with setCurrentInitiative(position) and then get tokenId with getInitiativeToken(). getInitiative() returns the init value. But changing initiative like that does other stuff that may not be wanted.

Actually, before I posted the request I was writing up an init panel wish list. I'll see what I can do for a rewrite. It's going to be in pseudo-code because I don't write java. I may take a look at the existing code (I'm better at reading java) to see if I see any simple fixes. I forget, didn't someone write a couple of init panel handlers?

I'm currently working on this for my game/framework using macroscript:

Code: Select all

<!-- moveTokenInInitiative(tokenToMove,targetTokenId,position,updateSort)
   tokenToMove - id of token to move
   targetTokenId - (opt) tokenId of token to move relative to (see position below) - default is current initiative token
   position - (opt) placement of new position - default is before
      first - move to first position
      last - move to last position
      before - insert before the token with current initiative
      after - insert after token with current initiative
   updateSort - (opt) 1 to update the moved tokens initiative value by normalizing the sort order.
      This will speed things up by not rebuilding the initiative panel and use the initiative sort instead
      default is 1 and will use sort, 0 to do rebuild of init panel.

   Move token in initiative panel (REDRAW THE WHOLE darn THING! Maybe.)
-->

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: [FREQ 1.4] Move a token in Initiative

Post by JamzTheMan »

One thing that I'd like to see as an option myself is, if you drag a token to reorder it, set it's initiative to match. Otherwise you see this "23, 19, 14, 22, 10" after dragging 22 down to just before 10. Normally this is ok but then if you resort for other reasons you loose this position. This happens sometimes if I have to adjust a token because of a delayed action...

I believe we can currently set initiative ok but haven't played with it in a while so ya, if you see little gotcha's note them down.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: [FREQ 1.4] Move a token in Initiative

Post by Full Bleed »

Since you're talking init... I'd love to have some Init events:

onReceiveInit
onEndInit
onChangeInit
onEndOfRound
onStartOfRound

And it would be awesome if there was PC and NPC versions.

Of course, I've built versions of these in my framework but they tend to carry some of the highest overhead in the game-flow (like building in exceptions for PC's and NPC's, determining what point of the init I'm in, having to loop through all tokens, etc.)... so anything that would optimize the process would be sweet.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Post Reply

Return to “MapTool 1.4”