#✅ | Hello I want to know how to...

1 messages · Page 1 of 1 (latest)

rose idol
#

I have 2 background musics, one its the main background music and the other is screen-specific

I want to fade-out the volume of the background music when i open a screen, and fade-in the screen-specific music when it opens, and viceversa when i go back to any other screen

how can i do that?

lean fieldBOT
# rose idol I have 2 background musics, one its the main background music and the other is s...

You can’t automatically “fade” audio in one built‑in action, but you can simulate it with a tiny action script that repeatedly nudges each audio element’s volume via set_audio_element_volume.

How to set it up

  1. Put your main background music in a universal layout (auto‑playing audio element); give it an easy ID like main_music.
  2. Create the screen‑specific layout and add that second audio element (e.g., screen_music). Enable it only for that screen.
  3. Add a Ticker (or use a listener) that runs while the screen layout is active. In its action script you’ll:
    • Read the current volumes with the audio_element_vol placeholder.
    • On screen open, lower main_music in small steps and raise screen_music in small steps by repeatedly calling set_audio_element_volume with calculated values.
    • When the screen closes (or when your layout unloads), reverse the steps to bring main_music back up and fade screen_music down.

A simple pattern is this:

IF current_volume(main_music) > target_main
  set_audio_element_volume -> new_volume = current - 0.05
ELSE
  set_audio_element_volume -> target value (e.g., 0)

You can use the audio_element_vol placeholder to fetch each element’s current volume and compare it in Is Number requirements. Run the ticker every 50–100 ms to make the fade smooth. Do the same flipped logic for screen_music (raise toward 1.0 while lowering the other).

If you prefer not to script the whole fade, you can simply trigger the set_audio_element_volume action twice (once to mute the other track, once to bring the new one to 100%) when the screen opens/closes. That’s faster but less smooth.

Need the exact action and placeholder names? Check the Action Scripts guide for set_audio_element_volume and the Placeholders page for audio_element_vol.

rose idol
#

can you provide me a complete and detailed example of how to do that?

lean fieldBOT
# rose idol can you provide me a complete and detailed example of how to do that?

Sure! Here’s a full example of how to simulate fading between your universal background music and a screen‑specific track using a Ticker + action script.

1. Audio setup

  • Universal layout: add an Audio element (ID main_music) with your main track. Set it to play automatically and loop.
  • Screen layout: add another Audio element (ID screen_music) with the screen-specific track. Let it autoplay when that layout loads.

2. Create a Ticker element

Place a Ticker element in the screen layout. Set it to tick frequently (e.g., tick delay 100 ms) and run “Normal” or “On Screen Load” mode so it updates while the screen is open.

3. Fade action script (ticker)

Right-click the ticker → Edit Action Script. Use this structure:

▶ IF – Is Number (compare $$value placeholder to 0.05) checking `audio_element_vol` for main_music
   └─ Set Audio Element Volume: `main_music:{"placeholder":"calc","values":{"expression":"{"placeholder":"audio_element_vol","values":{"element_identifier":"main_music"}} - 0.05","decimal":"true"}}`
▶ ELSE
   └─ Set Audio Element Volume: `main_music:0.0`
▶ IF – Is Number (compare to < 0.95) using `audio_element_vol` for screen_music
   └─ Set Audio Element Volume: `screen_music:{"placeholder":"calc","values":{"expression":"{"placeholder":"audio_element_vol","values":{"element_identifier":"screen_music"}} + 0.05","decimal":"true"}}`
▶ ELSE
   └─ Set Audio Element Volume: `screen_music:1.0`
  • The audio_element_vol placeholder (see Placeholders) reads the current volume.
  • The calc placeholder increments/decrements by 0.05 per tick; adjust the step or delay for smoother/faster fades.
  • Add Is Number requirements to keep the actions from overshooting (e.g., compare current volume with > 0.0 or < 1.0).
#

4. Fade back when screen closes

Use either:

  • Screen Close listener/action: add a ticker or listener that detects when the layout unloads (e.g., toggle a layout requirement or use a listener On Screen Closed) and reverse the logic (fade screen_music down while fading main_music up).
  • Or have a General Ticker running in a universal layout that checks if the screen’s layout is active (via a variable or Is Layout Enabled requirement) and applies the opposite fade.

5. Optional: store target volumes in variables

If you want to reuse steps for multiple screens, store target volumes (target_main, target_screen) in variables and only run the fade logic when those targets change.

📘 For more details see the Action Scripts guide (especially set_audio_element_volume) and the Placeholders list for audio_element_vol/calc.

Would you like me to help you build the exact ticker script with placeholder JSON you can paste in?

rose idol
#

Provide me any troubleshooting guide of what have i to check in case it wasn't working

lean fieldBOT
# rose idol Provide me any troubleshooting guide of what have i to check in case it wasn't w...

Here’s a quick troubleshooting checklist for when your music fade setup doesn’t work:

  1. Confirm your audio IDs
    Make sure the IDs you use in actions/placeholders match the actual element identifiers (right-click → “Copy Element Identifier”). Wrong IDs mean set_audio_element_volume and audio_element_vol fail silently.

  2. Check ticker is running

    • Ticker tick delay should be low (e.g., 100 ms).
    • Tick mode must actually run while the screen is open (use “Normal” or “Tick While Screen Open”).
  3. Verify requirements let the actions fire
    If you gate the fade logic with Is Number requirements, ensure they evaluate correctly. Catch edge cases by logging via Print to Log or temporarily removing requirements.

  4. Watch for volume clamping
    If your calc expression keeps going below 0 or above 1, add Is Number requirements like “current_volume > 0.0” or “< 1.0” before adjusting, so the value stops at 0/1.

  5. Ensure both audio elements are enabled
    The screen-specific audio must be loaded when the ticker runs (check layout loading requirements). If it hasn’t loaded, audio_element_vol returns nothing.

  6. Use placeholders & actions from docs
    Reference Action Scripts for set_audio_element_volume and Placeholders for audio_element_vol/calc to ensure you’re supplying valid JSON.

  7. Test without fading logic
    Temporarily set fixed volumes (e.g., set main_music:0 and screen_music:1) to verify the action path itself works before adding the fade loop.

If anything still acts up, describe what’s happening (e.g., “main music never fades out”) and I’ll suggest more targeted tweaks ☁️

lean fieldBOT
#
Thread Marked as Solved

This support thread has been marked as solved by @rose idol.

The AI helper is now disabled, but you can still continue the conversation if needed. Thank you for using our support system!