Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat message created with a macro is always in Common #54

Closed
kayhos opened this issue Oct 21, 2020 · 8 comments
Closed

Chat message created with a macro is always in Common #54

kayhos opened this issue Oct 21, 2020 · 8 comments

Comments

@kayhos
Copy link

kayhos commented Oct 21, 2020

Hello all,

I am triggering a macro from a MultiLevelTokens drawing area to speak as a token located elsewhere in the dungeon. When a player enters the drawing, it calls the below macro with the following arguments:

args[0] = V7AHiqGDjtQGvGtE
args[1] = "The Spider Queen blesses House Auvryndar! The battle to break House Freth's hold on the passages below brings victory after victory. We have seized key positions formerly held by our enemy. The defeat of House Freth is inevitable. Praise Lolth!"
args[2] = Elvish
args[3] = 2

The args[0] token knows Elvish and I have tried to trigger the macro with a non-elvish speaking character and an elvish speaking character. It always comes out the same in comon.

Here are my versions :
Foundry VTT v0.6.6
System: D&D 5E v0.98
Polyglot v1.3
Multileveltokens v1.3.4
// Speak a message from a specific token
//From Kekilla#7036's bubble macro 
//arguments required => args[0] === token_id
////////////////////////args[1] === chatContent
////////////////////////args[2] === language
////////////////////////args[3] === time in seconds

setTimeout(function() {
    let t = canvas.tokens.get(args[0]);
    if(t.actor?.data.data.attributes.hp.value === 0) {
        console.log("Speaker Token has 0 HP");
    } else {
        //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});
        ui.notifications.notify(args[1]);

        if(region !== null) {
            region.data.hidden == false;
            region.update({flags: {"multilevel-tokens": {disabled: true}}});
        }
  }
}, (args[3]*1000));
@kayhos
Copy link
Author

kayhos commented Oct 21, 2020

Might be linked to issue #37

@kakaroto
Copy link
Collaborator

kakaroto commented Oct 21, 2020

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)

@kayhos
Copy link
Author

kayhos commented Oct 22, 2020

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

@kakaroto
Copy link
Collaborator

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

@kayhos
Copy link
Author

kayhos commented Nov 3, 2020

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});

@kayhos
Copy link
Author

kayhos commented Nov 3, 2020

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.

@drewg13
Copy link

drewg13 commented Nov 5, 2020

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();

@kayhos
Copy link
Author

kayhos commented Nov 6, 2020

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

Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants