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

Lua function script always runs twice on X9D+ works correctly in Companion #3321

Closed
1 task done
stephendevelop opened this issue Mar 7, 2023 · 3 comments · Fixed by #3338
Closed
1 task done

Lua function script always runs twice on X9D+ works correctly in Companion #3321

stephendevelop opened this issue Mar 7, 2023 · 3 comments · Fixed by #3338
Labels
bug 🪲 Something isn't working triage Bug report awaiting review / sorting

Comments

@stephendevelop
Copy link

stephendevelop commented Mar 7, 2023

Is there an existing issue for this problem?

  • I have searched the existing issues

What part of EdgeTX is the focus of this bug?

Transmitter firmware

Current Behavior

I put a LUA script in SCRIPTS/FUNCTIONS folder
I make it run via "special functions" "Lua Script" action and put it behind a switch.

In the companion, the lua script is executed only once
On the taranis X9D+ running Edge TX v2.8.0 this is run twice.
On the Logical switches screen on the taranis, the Logical switch is only blinking on and off.

Tried to put it behind a logical switch or behind an edge switch, same behaviour, always run twice on the taranis X9D+, only runs once in the companion

Expected Behavior

Should only run once on the TaranisX9D+ and the behavior should be consistent between taranis and companion

Steps To Reproduce

  1. put simple lua script ( playsound ) in functions folder
  2. create logical switch that goes on for 0.1 second after a switch is down
  3. create special function that is activated on logical switch, action is the Lua Script

Just a simple script with "playFile" will expose the issue

Version

2.8.0

Transmitter

FrSky X9D+

Anything else?

No response

@stephendevelop stephendevelop added bug 🪲 Something isn't working triage Bug report awaiting review / sorting labels Mar 7, 2023
@stephendevelop stephendevelop changed the title Lua function script run twice on X9D+ works correctly in Companion Lua function script always runs twice on X9D+ works correctly in Companion Mar 8, 2023
@philmoz
Copy link
Collaborator

philmoz commented Mar 9, 2023

Lua scripts are run every 50ms.
Your logical switch is on for 100ms (0.1s) so the script in the special function can run twice before the switch turns off.

On my Mac, the simulator will sometimes run the script twice.

The 'play script' special function should probably have the '1x' repeat functionality implemented to handle this case.

@stephendevelop
Copy link
Author

Thank you for the explanation!

Maybe there's a better way to implement what I want to achieve:

What I want to achieve, is a LuaScript that plays one track and then increment a counter, on every flip of the momentary switch.
So that every time I flip the momentary switch, the next track is played
I want to use this to play the F3A pattern figures one by one.

@lshems
Copy link
Contributor

lshems commented Mar 10, 2023

You can perfectly make a function that only runs once bases on a variable déclarée outside thé function to check if it has run already. Search upvalues lus on Google.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working triage Bug report awaiting review / sorting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants