copyToken questions

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice


User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: copyToken questions

Post by wolph42 »

by the way
xavram wrote:Oh cool, documentation on wiki doesn't say that it returns the Id...excellent.

Any ideas on the positioning issue?
wiki wrote:The return type of this function is determined by the number of copies that you are making. If you are only creating a single copy of the token then a string containing the Tokens id, if you are making more than one copy then a JSON Array containing the Token ids of all the newly created Tokens is returned.
i've further updated the wiki to make it even more clear, also added the 'change after copy methods' and (tested) examples.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

Missed that! Thanks Wolph!

I have been without power at my house for 3 days (crazy wind storm knocked down like 8 power poles), so I'm looking forward to actually trying to get this to work over the weekend...:)

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

So, related to this...

the "MoveTokenFromNap" call that I was going to use requires the token id for the token that's on the other map. In my case, this is the "Resource" map.

I know the names of all the relevant tokens on that map, but not the Ids. And "FindToken" only works on the current map, right? So how do I get the Id of the token I want to move to my current map, without actually switching maps?

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

Re: copyToken questions

Post by aliasmask »

You can try using the name of token and see if that works. Sometimes the wiki won't specify some things that work. One common one is where ever token id is used, the token name may be able to be used. (but not always)

Other than that, changing maps is exactly what you do, but if you change the map back to the original they there is only a brief flicker on the screen. It doesn't actually need to reload everything.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

That actually did work, but moving the token to the map seems to have an odd behavior. Once moved, I can't get the token Id.

Code: Select all

[h : moveTokenFromMap("Spikes", "Resources" , 10000, 10000, 1)]
[h : droppedId = findToken("Spikes")]
[r : droppedId]
You would think this would display the token ID but it does not. it DOES move the token from the Resources map over to the current map.

But if I can't get the ID, certain functions aren't going to work. I need to be able to move that token and set some properties, so that I can THEN call the copyToken function on it.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: copyToken questions

Post by wolph42 »

ok thats really weird cause that should work. you *can* use the token name ALWAYS instead of the ID unless there are two tokens with the same name, then you don't know which one will be changed.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

So here's the test...

Code: Select all

[h : moveTokenFromMap("Spikes", "Resources" , 10000, 10000, 1)]
[h : droppedId = findToken("Spikes")]
[h : moveToken(8873.5,10633, 1, droppedId)]
[h : setTokenFacing(45, droppedId)]
The first time this is called, it moves the "Spikes" token from the Resource map to current map, at 10000, 10000.

If you call it a second time (when the spikes have already been moved to current map), THEN it moves them to 8873, 10633 and sets the rotation to 45.

But that, obviously, is a problem, the fact that it has to be called twice. Its almost like the same issues with copyToken, where you can't immediately access it.

Note that if i change this code to use "Spikes" instead of "droppedId", I get the same behavior.

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

Re: copyToken questions

Post by aliasmask »

There is likely some timing issues. When tokens need to be redrawn, that is done last. Perhaps change the facing and then move token? I recall doing something similar with states and moving a token where I had to move the token last for the state to take effect.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

I took the "setTokenFacing" line out completely, same results. Token never moves to the coodinates specified in "moveToken"

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

Re: copyToken questions

Post by aliasmask »

I did this test

Code: Select all

[h : moveTokenFromMap("MoveMe", "Grasslands" , 0, 0, 0)]
[h : id = findToken("MoveMe")]
[H, for(i,0,1000): "pause"]
[h: moveToken(2,2,0,id)]
And I can see the token move to 2,2 and then back to 0,0. It seems moving the token from another map is pretty much done last no matter what. I actually tried several things including using my custom macros:

Code: Select all

@@ @deferFunction
<!-- deferFunction(function,args)
   function - function to be deferred
   arg - arguments to be passed to function (json array)
-->
[H: function = arg(0)]
[H, if(argCount() >= 2), code: {
   [H: args = arg(1)]
   [H, if(json.type(args) != "ARRAY"): args = json.append("",args)]
};{
   [H: args = ""]
}]
[H, if(currentToken() == ""): target = getMacroLocation();target = currentToken()]
[H: deferArgs = json.append("",function,args)]
[H: link = macroLinkText("execFunction@"+getMacroLocation(),"none",deferArgs,target)]
[H: execLink(link,1)]

!!


@@ @execFunction
[H: function = arg(0)]
[H: args = arg(1)]
[H: argList = ""]
[H, foreach(arg,args), code: {
   [H: argList = listAppend(argList,"arg"+roll.count)]
   [H: set("arg"+roll.count,arg)]
}]
[H: fnStr = strformat("%{function}(%{argList})")]
[H, C(500):"pause"]
[H: eval(fnStr)]

!!
With the following code:

Code: Select all

[h: moveTokenFromMap("MoveMe", "Grasslands" , 0, 0, 0)]
[H: args = json.append("",2,2,0,"MoveMe")]
[H: am.play.deferFunction("moveToken",args)]
And I got the same result. You see the token move to 0,0 then to 2,2 and back to 0,0.

I would treat tokens moving from another map as if they were newly created with the same limitations.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

Drat...okay, I need to take a step back on how I envisioned this working and tackle it from a different angle.

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

Re: copyToken questions

Post by aliasmask »

xavram wrote:Drat...okay, I need to take a step back on how I envisioned this working and tackle it from a different angle.
So, what are you trying to do specifically.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: copyToken questions

Post by xavram »

Well, what I had was this.

Dropped weapon makers (Oil, spikes, paint, etc, etc) were off on a seperate "Resources" map, with all of their statistics already set in the properties of the weapon.

When a player fires one of these weapons, I was going to move the "resource" token onto the "game" map, position it correctly, and set some additional properties. Then i was going to copyToken on this resource token, then move the resource token BACK to the "Resources" map, to be ready for the next time.

Unfortunately, after the "moveTokenFromMap" call, I can't manipulate the resource token.

In the end, I think I'm going to have to have a "baseDroppedItem" token on the "game" map. I will then have to size it, set the image, set the base properties and all that, then copy it, etc, etc. Effectively, I'm going to have to create a token "from scratch" each time, instead of being able to save a bunch of steps by using "pre-set" resource tokens.

But it looks like that's the road I'm going to have to travel to make this work.

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

Re: copyToken questions

Post by aliasmask »

Best method is to switch to resource map, make your changes then copy the token to the target map. It'll give you a minor flicker when done, but that's it. Or at the start you can copy all the needed resources to the map and then you can adjust and move without the flicker.

Post Reply

Return to “Macros”