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

[BUG] Multiple variable substitutions fail from button presets #2837

Closed
2 tasks done
premultiply opened this issue Apr 14, 2024 · 3 comments
Closed
2 tasks done

[BUG] Multiple variable substitutions fail from button presets #2837

premultiply opened this issue Apr 14, 2024 · 3 comments
Labels
BUG Something isn't working

Comments

@premultiply
Copy link

Is this a bug in companion itself or a module?

  • I believe this to be a bug in companion

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I try to add multiple internal module instance variables to a button text by button preset code.

Everything works fine by using the button editor manually.

But the replacement by code using a preset only replaces the first occurence of a variable correctly.

So for example if this is the final (manually working) button text:
P/T Pos.\n$(UE150:panPositionDeg)°\n$(UE150:tiltPositionDeg)°

It should be generated by this preset code:

presets['pan-tilt-position'] = {
            type: 'button',
            category: 'Pan/Tilt',
            name: 'Pan/Tilt Position',
            style: {
                text: 'P/T Pos.\\n$(generic-module:panPositionDeg)°\\n$(generic-module:tiltPositionDeg)°',
                size: '14',
                color: colorWhite,
                bgcolor: colorBlack,
            },
...
}

But the after dropping the preset to the button only the first occurence get substituted:
P/T Pos.\n$(UE150:panPositionDeg)°\n$(generic-module:tiltPositionDeg)°

The more variables are added to the button text string the failing substitutions shuffle around.

Steps To Reproduce

  1. Add a button text with multiple variable substitutions to the preset code using $(generic-module:XXXXX)
  2. Drag and Drop this preset to a button.
  3. See that generic-module is not corretly substituted by the device instance name but left as generic-module in the resulting button text.

Expected Behavior

All $(generic-module:XXXXX) entries are substituted correctly by the device instance name adressing an existing module variable and showing the correct content of all variables on the button.

Environment (please complete the following information)

- OS: Windows 10 LTSC
- Browser: Firefox 124.0.2
- Companion Version: 3.2.2 (3.2.2+6688-stable-7417d2a0)

Additional context

No response

@premultiply premultiply added the BUG Something isn't working label Apr 14, 2024
@premultiply premultiply changed the title [BUG] [BUG] Multiple variable substitutions fail from button presets Apr 14, 2024
@Julusian
Copy link
Member

Interestingly this worked sometimes. I think the difference is that if the new name was longer, then it would sometimes miss a later variable, depending on how much later it started.
Fixed now though

@premultiply
Copy link
Author

Mmmmh. It is fixed for two variables now but has the old issue on three variables to be replaced:

$(generic-module:title)\n$(generic-module:model)\n$(generic-module:version)

Should be replaced to $(CX350:title)\n$(CX350:model)\n$(CX350:version) but is rewritten as $(CX350:title)\n$(CX350:model)\n$(generic-module:version) on the button.

@Julusian
Copy link
Member

@premultiply yep, there was a stupid mistake in my fix..
This time I've added some unit tests with your test cases, so we know that they are both fixed and happy.

I'll make sure this new fix gets into 3.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants