Code Monkey home page Code Monkey logo

Comments (8)

kayhos avatar kayhos commented on July 29, 2024

Might be linked to issue #37

from fvtt-module-polyglot.

kakaroto avatar kakaroto commented on July 29, 2024

I think the issue is in the macro command :
$(`#polyglot select option [value=${args[2]}]`).attr("selected","selected");

It should probably be like this instead :
$(`#polyglot select`).val(args[2]);

Setting the option as selected wouldn't change the actual select's value I think. Do you actually see it change in the UI ? If not, try the above and see if it works.

Though you should use the language id not its translated string (so elvish instead of Elvish)

from fvtt-module-polyglot.

kayhos avatar kayhos commented on July 29, 2024

I had the "bright" idea of upgrading Foundry to 0.7.5... same behavior as before.

Sad to report that the changed line triggers an error in the console:

SyntaxError: private fields are not currently supported
    _doMacros http://192.168.1.*:30000/modules/multilevel-tokens/multilevel.js:856
    _onUpdateToken http://192.168.1.*:30000/modules/multilevel-tokens/multilevel.js:1579
    _call http://192.168.1.*:30000/scripts/foundry.js:2426
    callAll http://192.168.1.*:30000/scripts/foundry.js:2386
    callOriginalFunction http://192.168.1.*:30000/modules/**furnace**/Patches/Patches.js:57
    <anonymous> http://192.168.1.*:30000/modules/**furnace**/QoL/Debug.js:33
    _handleUpdateEmbeddedEntity http://192.168.1.*:30000/scripts/foundry.js:29647
    _handleUpdateEmbeddedEntity http://192.168.1.*:30000/scripts/foundry.js:33793
    updateEmbeddedEntity http://192.168.1.*:30000/scripts/foundry.js:29615
multilevel.js:859:21
    _doMacros http://192.168.1.*:30000/modules/multilevel-tokens/multilevel.js:859
    _onUpdateToken http://192.168.1.*:30000/modules/multilevel-tokens/multilevel.js:1579
    _call http://192.168.1.*:30000/scripts/foundry.js:2426
    callAll http://192.168.1.*:30000/scripts/foundry.js:2386
    callOriginalFunction http://192.168.1.*:30000/modules/**furnace**/Patches/Patches.js:57
    <anonyme> http://192.168.1.*:30000/modules/**furnace**/QoL/Debug.js:33
    _handleUpdateEmbeddedEntity http://192.168.1.*:30000/scripts/foundry.js:29647
    _handleUpdateEmbeddedEntity http://192.168.1.*:30000/scripts/foundry.js:33793
    updateEmbeddedEntity http://192.168.1.*:30000/scripts/foundry.js:29615

from fvtt-module-polyglot.

kakaroto avatar kakaroto commented on July 29, 2024

Those errors clearly say they're from multilevel tokens module, it has nothing to do with chat messages or polyglot. Try the macro on its own, without the timeout and all the other stuff around it and see if it works

from fvtt-module-polyglot.

kayhos avatar kayhos commented on July 29, 2024

Heya Kakaroto, triggering the macro without all the extra stuff still happens on the polyglot line.

With the following macro, I get an error about Private Fields not supported

    let t = canvas.tokens.get(args[0]);
        //target token

        //set language?
        $(`#polyglot select).val(args[2]);

         ChatMessage.create(    
        { 
            speaker : { token : t, actor : t.actor, scene : canvas.scene },
            content : args[1],
            type : CONST.CHAT_MESSAGE_TYPES.IC,
        },{chatBubble : false});

With this script, there is no error, but the message is always in common (even passing elvish as a parameter)

    let t = canvas.tokens.get(args[0]);
        //target token

        //set language?
        $(`#polyglot select option [value=${args[2]}]`).attr("selected","selected");

         ChatMessage.create(    
        { 
            speaker : { token : t, actor : t.actor, scene : canvas.scene },
            content : args[1],
            type : CONST.CHAT_MESSAGE_TYPES.IC,
        },{chatBubble : false});

from fvtt-module-polyglot.

kayhos avatar kayhos commented on July 29, 2024

I'm a moron... I never noticed that the code you suggested was missing a `

This almost works:

    let t = canvas.tokens.get(args[0]);
        //target token

        //set language?
        $(`#polyglot select`).val(args[2]);

         ChatMessage.create(    
        { 
            speaker : { token : t, actor : t.actor, scene : canvas.scene },
            content : args[1],
            type : CONST.CHAT_MESSAGE_TYPES.IC,
        },{chatBubble : false});

The issue is that if the triggering token does not speak the required language, it simply outputs in common. Those tests are done on a GM account btw.

from fvtt-module-polyglot.

drewg13 avatar drewg13 commented on July 29, 2024

I was working on this exact problem and your code got me most of the way there and advice from kakaroto on Discord finished the job. Here's code that does the trick by switching control to a "speaking" token that has the target language enabled and then back to the player token afterwards:

let speakactor = game.actors.entities.find(c => c.name === args[0]);
let speaktoken = canvas.tokens.placeables.find(p => p.name === args[0]);
let playertoken = token;

speaktoken.control();

$(`#polyglot select`).val(args[2]);

ChatMessage.create(    
  { 
   speaker : { token : speaktoken, actor : speakactor, scene : canvas.scene },
   content : args[1],
   type : CONST.CHAT_MESSAGE_TYPES.IC,
  },{chatBubble : false});

playertoken.control();

from fvtt-module-polyglot.

kayhos avatar kayhos commented on July 29, 2024

Welp, you're awesome @drewg13 ... I should have though of that.

Thanks guys!

from fvtt-module-polyglot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.