Dynamic music

  • #10, by afrlmeWednesday, 08. July 2015, 23:34 6 years ago
    Yes you could create a loop in the editor using the jump to x action part function or you could create a mainLoop event function with Lua script.

    If you use the editor method then you need to make sure you create it inside of a called by other action block & quit the action inside of an at end of scene action to kill the loop.

    Imperator

    6935 Posts


  • #11, by Simon_ASAThursday, 09. July 2015, 11:05 6 years ago
    Strange.. I don't know what I' m doing wrong but nothing I try is working.

    Right now I have 3 action scripts in my scene properties:

    1 - Called by other action
    Plays randomly 3 background musics with random silences between each (based on the script 6 messages above, except I have replaced the 'Play Sound' action by the 'Change Background Music' action)

    2 - At beginning of scene
    A loop that calls script 1 constantly in the scene (loop created with action Jump)

    3 - At scene end
    An action that stops the loop

    What happens:
    When I start the scene, the first script starts well. The music is set as the new background music and plays. However when the music ends, it doesn't use the action script 1: there is no silence and it doesn't load a new music. Instead, the current one loaded as background music loops infinitely. Do you see what I mean?

    Great Poster

    321 Posts

  • #12, by afrlmeThursday, 09. July 2015, 13:43 6 years ago
    I take it script one contains a set random value action part & an if query to decide which music to play based on the random value?

    As for the loop block you should add a pause value either to the beginning of the block or just before the jump to x action part.

    Imperator

    6935 Posts

  • #13, by Simon_ASAThursday, 09. July 2015, 14:18 6 years ago
    Yes script 1 contains a set random value & an if query.
    I'll try the pause in the loop block, I like this idea. Adding a pause here and there often solves my issues grin

    Great Poster

    321 Posts

  • #14, by Simon_ASAThursday, 09. July 2015, 14:40 6 years ago
    No it didn't fix the problem. It's still the same sound playing in loop. I'll check my action script again to make sure that I didn't make a mistake. Anyway thanks for your help AFRL.

    Great Poster

    321 Posts

  • #15, by afrlmeThursday, 09. July 2015, 14:53 6 years ago
    Could you post some screenshots of all the relevant actions regarding what you are trying to do? Or a video maybe?

    Imperator

    6935 Posts

  • #16, by Simon_ASAThursday, 09. July 2015, 17:42 6 years ago
    Ok I'll post some screenshots if I definitely fail.

    For the moment I try to sort my actions differently, just in case. Regarding this, I have a question about the Jump action:
    if you Jump to action part #1 (absolute), does it Jump to the very first action in the list, or to the first action in the If query? Because maybe that's where I'm mistaken.

    Great Poster

    321 Posts

  • #17, by afrlmeThursday, 09. July 2015, 17:47 6 years ago
    absolute #1 is beginning of action list.

    relative -2 for example is 2 actions back from the jump to x action part.

    Imperator

    6935 Posts

  • #18, by Simon_ASAThursday, 09. July 2015, 19:30 6 years ago
    I cannot upload the screenshots today, so I'll just write everything.

    What I want to do:



    I have 3 musics for my current scene. I want to play them randomly, and I want a random silence between each.
    I try to do it with actions betcause I make too many mistakes with code.

    Problem:



    When 1 of the 3 musics is loaded as the new background music, it loops endlessly and the other musics never play.

    What I did:



    I have created a variable named "choose_music" that randomly takes values between 1 and 3.
    I have created another variable named "delay" that takes a random value between 10 and 120, in order to define the length of the silence.

    Script1: Called by other action

    if value 'choose_music' = 1
    change background music of scene 'Current scene' to 'music1.ogg'
    wait until sound 'music1.ogg' is finished
    pause for 'delay" seconds
    end if

    if value 'choose_music' = 2
    change background music of scene 'Current scene' to 'music2.ogg'
    wait until sound 'music2.ogg' is finished
    pause for 'delay" seconds
    end if

    if value 'choose_music' = 3
    change background music of scene 'Current scene' to 'music3.ogg'
    wait until sound 'music3.ogg' is finished
    wait until sound stinger2.ogg is finished
    end if

    Jump to action part #1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20



    Script2: At beginning of the scene

    This script loads Script1 and makes a loop, in order to call the script all the time and refresh the background music when it is finished.
    I have created a condition 'loop_music' in order to break the loop later.

    if condition 'loop_music' is true
    pause for 1 second
    call action 'Script1' -- above
    pause for 1 second -- just to be sure
    jump to action part #1
    end if
    1
    2
    3
    4
    5
    6
    7


    Script3: At end of scene

    This script breaks the loop in Script2

    Change condition 'loop_music' to false
    1
    2


    That's all I have kept right now. I have tried a lot of different actions in different orders, but it never worked. I hope you see what I'm trying to do. Thanks for your help!

    Great Poster

    321 Posts

  • #19, by afrlmeThursday, 09. July 2015, 20:43 6 years ago
    I believe what you are doing wrong is misusing the wait until sound finishes action part. Background music is not a sound. It's a single file that has been linked to the scene itself & will always loop meaning it will never actually end.

    set random value 'choose_music' between 1 and 3
    set random value 'delay' between 10 and 120

    if value 'choose_music' = 1
    change background music of scene 'current scene' to 'music1.ogg'
    pause for 'duration' milliseconds
    end if

    if value 'choose_music' = 2
    change background music of scene 'current scene' to 'music2.ogg'
    pause for 'duration' milliseconds
    end if

    if value 'choose_music' = 3
    change background music of scene 'current scene' to 'music3.ogg'
    pause for 'duration' milliseconds
    end if

    execute a script > 'see below'

    pause for 'delay' seconds

    jump to action part #1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24

    game.CurrentScene.BackgroundMusic = emptyObject -- remove bgm.
    1
    2


    I think.

    P.S: you didn't need a condition. Just execute this action block at the beginning of the scene. At end of scene add a quit action action part linked to the block containing the loop.

    Imperator

    6935 Posts

  • #20, by Simon_ASAThursday, 09. July 2015, 22:35 6 years ago
    That's what I thought for the "wait until sound is finished" that doesn't stop the BGM. However I had already tried to replace it. It is possible to stop the BGM with the action "change background music of scene 'current scene' to '" (if you don't choose a music file, it will just stop playing the BGM, so it's the same result as the script).

    Anyway, the problem is still the same, unfortunately roll
    When a music is played as BGM it just stays and plays in loop. It's as if the action script didn't exist.

    I'll make more tests tomorrow, I'm probably tired and making mistakes!

    Great Poster

    321 Posts

Write post