copyToken issue, X, Y cords not seeming to work?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
User avatar
celestian
Dragon
Posts: 276
Joined: Mon May 17, 2010 3:29 pm

copyToken issue, X, Y cords not seeming to work?

Post by celestian »

I have a set of tokens that store spells and another that stores monsters. I'd like to be able to let the user flip a setting and it "copy" the DB they want to use (1e or 2e). To that end I've created a function that should do just what I want but it seems to NOT place the token where the old one was.

Code: Select all

[h: '<!-- change DB token from #e to DB -->']
[H: numArgs = argCount()]
[h: assert(!(numArgs<3),"To few arguments to function "+getMacroName()+"(libMapName,libName,dbVersion). "+getMacroName()+"@"+getMacroLocation())]
[h: 'example usage to change Spells DB to 2e: changeDB("Framework - Library","Lib:Spells","2e")']
[h: 'example usage to change MM DB to 1e: changeDB("Framework - Library","Lib:MM","1e")']

[H: libMapName = arg(0) ]
[H: finalName = arg(1) ]
[H: dbVersion = arg(2) ]

[h: currentMap = getCurrentMapName()]

	[h: setCurrentMap(libMapName)]
	[h: tokenID = findToken(finalName)]

	[h: assert(tokenID !="", strformat("Unable to find original DB token %{finalName}, aborting! <br>"),0)]

	[h: CurrentX = getTokenX(1, tokenID)]
	[h: CurrentY = getTokenY(1, tokenID)]

	[h: replacementDBToken = strformat("%{finalName}:%{dbVersion}")]
	[h: replacementExists = findToken(replacementDBToken)]
	[h, if (replacementExists == ""), code :{
		[h: broadcast(strformat("Unable to find replacement DB Token %{replacementDBToken}, aborting! <br>"),"gm")]
		[h: abort(0)]
	};{}]

	
	[h: updates = strformat("{name: '%{finalName}',x: '%{currentX}',y: '%{currentY}' }")]
	
	[h: copyToken(replacementDBToken,1,libMapName,updates)]

	[h: removeToken(tokenID)]

[h: setCurrentMap(currentMap)
Before the macro is run "Lib:MM" is @ X, Y: -12500, 5000.

Code: Select all

[changeDB("Framework - Library","Lib:MM","1e")]
After the macro is run the "copy" is placed at -625000, 250000 (every time).

The macro above SHOWS the X, Y as "-12500, 5000" and that's also what is placed into the "updates" var for copyToken.

Anyone have any theories?

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

Re: copyToken issue, X, Y cords not seeming to work?

Post by wolph42 »

I'm guessing you mixed up grid coords and pixel coords. If you divide the two x coords and check the outcome with your map settings, you can know for sure

User avatar
celestian
Dragon
Posts: 276
Joined: Mon May 17, 2010 3:29 pm

Re: copyToken issue, X, Y cords not seeming to work?

Post by celestian »

wolph42 wrote:I'm guessing you mixed up grid coords and pixel coords. If you divide the two x coords and check the outcome with your map settings, you can know for sure
You were correct. I had thought the copyToken() would use the default method (1). I tweaked the code for the updates to this and it worked:

Code: Select all


[h: updates = strformat("{name: '%{finalName}',x: '%{currentX}',y: '%{currentY}', useDistance: 1, delta: 0 }")]

"useDistance" set to 1. I also added "delta" set to 0 just to be safe.

Thanks!

Post Reply

Return to “MapTool”