PDA

View Full Version : Assigning a tokencontrol from a file



kalannar
July 30th, 2014, 18:00
Is there a way to assign tokens to the tokencontrol from a graphic png file, like the icon option? Making an extension that I want to have a list of tokens characters can drop on to a grid.

Trenloe
July 30th, 2014, 18:20
The token will have to be a valid imagenode within the campaign database environment. Then use tokencontrol.populateFromImageNode: https://www.fantasygrounds.com/refdoc/tokencontrol.xcp#populateFromImageNode

For an example, see the linkToken() function in the CoreRPG ruleset in ct\scripts\ct_entry.lua

Or, if you want to use the filename directly related to the FG application directory (or a module) then use tokencontrol.setPrototype: https://www.fantasygrounds.com/refdoc/tokencontrol.xcp#setPrototype Keep in mind the warning for this function - that direct manipulation of the string is not recommended.

kalannar
July 30th, 2014, 18:27
Can you load graphics into a image node in an extension like you do icons?

Trenloe
July 30th, 2014, 18:39
Can you load graphics into a image node in an extension like you do icons?
An imagenode is a FG database entry, so you can't specifically load individual images easily that way from an extension as an extensions doesn't contain FG database entries (you might be able to write some onInit() code to do it - populating the database when it runs) and image nodes are not seen as the same type of resource as icons are. You can create a module that contains all of the image nodes. But, it might be easier to use the setPrototype API command (I edited my post above to include info about this) - but you would still need to reference the token image files in a FG appropriate way.

The best way would be to have your tokens in a token module and access them that way. For example, to access the small letter "T" token from the letters module supplied with FG and store it on a token control I'd use: <tokencontrol>.setPrototype("tokens/Small/t.png@Letter Tokens") @Letter Tokens is the name of the module and tokens/Small/t.png is the path and filename within the module.

Using token modules is the recommended way to do it - as you aren't reliant on the correct tokens being in the correct directory in the freeform <FG app data>\tokens directory, and you can close the token module to save resources if you don't need them for a campaign.

Trenloe
July 30th, 2014, 18:54
An example of using <tokencontrol>.setPrototype can be found in CoreRPG, ct\scripts\ct_target.lua in the onRefChanged() function. This reads the token filename from the combat tracker database <token> entry (this could be an FG app folder related filename or a module filename) and uses the string to set the token for the tokencontrol using setPrototype.

kalannar
July 30th, 2014, 22:11
Ok did what you said and created a token module and used it to create the prototype, so working as i need it. Thank you.

Now next question. How can I set the scale of the token from the tokencontrol when i drop it on to an imagecontrol? Can i set the scale in the tokencontrol, so when i drop it on the imagecontrol it has the scale i want?

damned
July 30th, 2014, 22:25
i think the scale is 100%.
when you attach a token to a npc/monster it then uses the small, medium, large of the monster to set the scale...

Trenloe
July 30th, 2014, 22:53
Now next question. How can I set the scale of the token from the tokencontrol when i drop it on to an imagecontrol? Can i set the scale in the tokencontrol, so when i drop it on the imagecontrol it has the scale i want?
You can't set the scale of a token before it is added to the map.

However, depending on the ruleset, there may be 100% or 80% token scaling if a grid has been added to the image. By default, in rulesets that support this, token scaling is turned on and at 80% - which means that any tokens added to an image with a grid will be scaled to fit 80% within the grid, unless the ruleset has a size set in the linked combat tracker entry. These settings are available in most rulesets based on CoreRPG and some others.

More info on scaling here: https://www.fantasygrounds.com/wiki/index.php/Tokens#Scaling