Closed Coyotito007 closed 1 year ago
Check if there are any errors or warnings in the JavaScript console (either after loading the world or after dragging a token). If that doesn't help, please paste your entire module code here. Seeing the entire code helps a lot at locating potential issues.
Thank you very much for your time !
I use foundry 10 build 303 and the drag ruler version 1.13.4 (1.13.8 is not yet available ofr download on foundry).
Here is the code of the additional module i've copied, with only one slight modification included "const baseSpeed = actor.system.attributes.agility.value" (i figured the part with "the not wearing armor" couldn't harm so i left it even if i dont need it since i m very bad at all this and didnt want to create new syntax mistakes) :
Hooks.once("dragRuler.ready", (SpeedProvider) => { class FictionalGameSystemSpeedProvider extends SpeedProvider { get colors() { return [ {id: "walk", default: 0x00FF00, name: "hello.speeds.walk"}, {id: "dash", default: 0xFFFF00, name: "hello.speeds.dash"}, {id: "run", default: 0xFF8000, name: "hello.speeds.run"} ] }
getRanges(token) {
const baseSpeed = actor.system.attributes.agility.value
const ranges = [
{range: baseSpeed*5, color: "walk"},
{range: baseSpeed*10, color: "dash"}
]
if (!token.actor.data.isWearingArmor) {
ranges.push({range: baseSpeed * 20, color: "dash"})
}
return ranges
}
}
dragRuler.registerModule("hello", FictionalGameSystemSpeedProvider)
})
As far as i can tell, the only error message i get in the console log pertaining to either drag ruler or my module "hello" is this one :
Error: You are accessing the MYZActor#data object which is no longer used. Since V10 the Document class and its contained DataModel are merged into a combined data structure. You should now reference keys which were previously contained within the data object directly. at logCompatibilityWarning (commons.js:1692:19) at MYZActor._logV10CompatibilityWarning (commons.js:6642:14) at get data [as data] (commons.js:6542:24) at FictionalGameSystemSpeedProvider.getRanges (hello.js:21:21) at getRangesFromSpeedProvider (api.js:90:39) at DragRulerRuler.dragRulerGetColorForDistance (ruler.js:468:28) at DragRulerRuler.highlightMeasurementNative (foundry_imports.js:212:22) at DragRulerRuler.performPostPathfindingActions (ruler.js:187:34) at DragRulerRuler.measure (ruler.js:133:16) at DragRulerRuler.scheduleMeasurement (foundry_imports.js:153:8) at DragRulerRuler.onMouseMove (foundry_imports.js:145:22) at Token.onEntityLeftDragMove (main.js:159:37) at Token.onEntityLeftDragMoveSnap (main.js:153:23) at 🎁call_wrapper [as call_wrapper] (libWrapper-wrapper.js:616:16) at 🎁Token.prototype._onDragLeftMove#0 (libWrapper-wrapper.js:189:20) at MouseInteractionManager.callback (foundry.js:27872:45) at MouseInteractionManager._handleDragMove (foundry.js:28229:17) at MouseInteractionManager._handleMouseMove (foundry.js:28201:22) at a.emit (index.js:202:33) at r.dispatchEvent (interaction.min.mjs:8:12235) at r.processPointerMove (interaction.min.mjs:8:17255) at t.recursiveFindHit (interaction.min.mjs:8:4098) at t.findHit (interaction.min.mjs:8:4157) at r.processInteractive (interaction.min.mjs:8:12841) at r.onPointerMove (interaction.min.mjs:8:16687)
I also tried modifying the system.js file of the module to include this attribute for the system "mutant-year-zero" but it didnt seem to work at all, that was a long shot...
EDIT
When i try to drag a token, i get these error messages:
api.js:99 ReferenceError: actor is not defined at FictionalGameSystemSpeedProvider.getRanges (hello.js:12:31) at getRangesFromSpeedProvider (api.js:90:39) at DragRulerRuler.dragRulerGetColorForDistance (ruler.js:468:28) at DragRulerRuler.highlightMeasurementNative (foundry_imports.js:212:22) at DragRulerRuler.performPostPathfindingActions (ruler.js:187:34) at DragRulerRuler.measure (ruler.js:133:16) at DragRulerRuler.scheduleMeasurement (foundry_imports.js:153:8) at DragRulerRuler.onMouseMove (foundry_imports.js:145:22) at Token.onEntityLeftDragMove (main.js:159:37) at Token.onEntityLeftDragMoveSnap (main.js:153:23) at 🎁call_wrapper [as call_wrapper] (libWrapper-wrapper.js:616:16) at 🎁Token.prototype._onDragLeftMove#0 (libWrapper-wrapper.js:189:20) at MouseInteractionManager.callback (foundry.js:27872:45) at MouseInteractionManager._handleDragMove (foundry.js:28229:17) at MouseInteractionManager._handleMouseMove (foundry.js:28201:22) at a.emit (index.js:202:33) at r.dispatchEvent (interaction.min.mjs:8:12235) at r.processPointerMove (interaction.min.mjs:8:17255) at t.recursiveFindHit (interaction.min.mjs:8:4098) at t.findHit (interaction.min.mjs:8:4157) at r.processInteractive (interaction.min.mjs:8:12841) at r.onPointerMove (interaction.min.mjs:8:16687) getRangesFromSpeedProvider @ api.js:99 foundry.js:727 Foundry VTT | Error thrown in hooked function 'undefined' for hook 'updateToken'
foundry.js:747 TypeError: Error thrown in hooked function 'undefined' for hook 'updateToken'. entry.fn is not a function
at #call (foundry.js:724:20)
at Hooks.callAll (foundry.js:681:17)
at ClientDatabaseBackend.callback (foundry.js:12824:13)
at foundry.js:12804:43
at Array.map (
thx again
Change the first line in getRanges
to be const baseSpeed = token.actor.system.attributes.agility.value
Why does it have to be that? In programming, you need to always tell the software exactly where it's going to get it's values from. Since actor
hasn't been defined in your function before, Foundry doesn't know where to look. That's why you need from some known location. That location is the token currently being dragged. Drag Ruler gives you the currently dragged token at the start of the get ranges
function. That token is stored in the variable named token
(as defined in the parentheses - you could change that if you wanted to). Now you can start at that token and work your way to the desired value from there.
const baseSpeed = token.actor.system.attributes.agility.value
basically tells foundry: I have a variable called token
(as declared in the parenthesis above). In that variable, look for a value named actor
(which represents that token's actor). Within that value, look for a value named system
(which is where game system specific information is stored), within that look for a value named attributes
, within that look for a value named agility
, and within that look for a value named value
. Take that last value and store it into a new variable called baseSpeed
.
The reason why you can get away with actor.system.attributes.agility.value
(without the token.
) in Drag Rulers configuration menu is that the Generic Speed Provider is built so that it always assumes you're starting at the currently dragged token. The Drag Ruler API doesn't make those assumptions to give you as much flexibility as possible when writing your integration module. For that reason you have to explicitly specify that you're starting from the dragged token.
I hope this helps a bit in understanding what's going :)
Reading your message feels like getting a breath of fresh air after 3 minutes under water :)
And it works (of course) !
Thank you very much.
Glad I could help!
Im trying to adapt the module to mutant year 0.
i can get the module to use actor.system.attributes.agility.value (for instance) as speed attribute in the settings panel.
But i would like to modify this setting to be closer to the rules (which could give something like this attributes 5 and 10).
So i tried using the api call as explained in the tutorial and the forum answer about this implementation by reproducing the example in the module documentation (API section) and replacing the base speed by actor.system.attributes.agility.value, since it works in the general settings.
but the line " const baseSpeed = actor.system.attributes.agility.value " gives a resul where all distances are passable at walk speed (ie in green).
Could anybody give me a clue ? I m totally new to this and i m sure i sound a bit confused...
Thank you