Random Music with Visionaire?

  • #1, by MortoAllegroMonday, 02. March 2015, 17:16 10 years ago
    Is Possible to set a Random Music on Background in visionaire?

    i mean, i think what i need is one "getTimer" that at the end choose from an array of tre Songs, and than play that song.

    i have all scene properties set with "continue music from previous scene".

    And the last one thing i needed is a way to "kill Sound" that i'll use when in my game i'll need to stop the music that are playing (because if it is random i don't know which one i need to stop) and than play one directly choose by me.

    thats because some times i need to playing song that are much more related with the cut scene.

    any one know if there is a

    getTimer, Array of music and KillAllSound code?

    any clue?


    44 Posts

  • #2, by afrlmeMonday, 02. March 2015, 18:17 10 years ago
    1. Don't use the continue music option. It's not recommended as it will continue whatever music was playing in the last scene, even if said music was in the menu & you have just loaded a game. It will not store the music that it was playing last, which means it will play music from the last scene / menu you were on or nothing at all.

    The recommended method for continue music from previous scene is to add the same audio file to each of the scenes that you want it to play the same music for. The engine will automatically continue playing the music when you change to a new scene if the audio file is the same.

    2. You could do this with if query actions or with Lua script.

    What you would do for the action part version is create a value & call it something like bg_music. Whenever you wanted to select a random audio file you could do something like.
    set random value in 'bg_music' between 0 and 10
    if value 'bg_music' is 0
     play and loop sound 'bg1.ogg' infinitely
    end if
    if value 'bg_music' is 1
     play and loop sound 'bg1.ogg' infinitely
    end if
    ... -- etc

    You could do the same thing with Lua script too, but I'm not going to write out the necessary code for that, right now.


    7281 Posts

  • #3, by MortoAllegroTuesday, 03. March 2015, 00:24 10 years ago
    umm, sorry but, like this you have to setup that action on every scene you have, and there is not, for what i know about visionaire, nothing like"if background is already playing a song do nothing."

    that because i dont want music in loop, but only, a 60 sec song chosen randomly by a list of songs.

    the other point is: if i don't know which one are still playing, how i can setup the action part "stop currently playing sound" that want the name of the song to make it stop?

    what i'll try to do is to set-up a timer (2 minutes) that randomly choose from a list of songs(that are like 30sec song or even 60sec). Play it, an than restart...and if a songs are still playing, doing nothing and restare the timer..

    i dont think is possible without Lua scripting, but there is no "class" explanation written on the wiki...there is no a complete documentation.


    44 Posts

  • #4, by afrlmeTuesday, 03. March 2015, 01:26 10 years ago
    Class explanation?

    The number returned from the value could also be used for determining which audio file to stop. No you don't have to setup the main action blocks for each scene. You only need to create them once as called by other action's, then you only need to call the required called by other action with the call action action part.

    The editor audio & Lua audio controls are not linked. You can start, stop, pause & manipulate audio using the openAL audio engine with Lua script, but you can't manipulate audio started via action parts of the editor. You can however change the currently playing background audio file linked to a scene with Lua script & the data structure field VSceneBackgroundMusic.
    game.CurrentScene.BackgroundMusic = "sounds/music/test.ogg"

    ...I've not actually tried scripting this before, so not sure if it's correct. If you replace the current bg music then it should automatically stop whatever is playing & set the new one playing, but again, I'm not sure as I've not tested it.

    P.S: the mini-code example I provided above may not work as it's the new shorthand scripting method & the shorthand is not all working in the current public build. I use a team build which has newer features & various bug fixes... here's the longhand method.
    getObject("Game.GameCurrentScene"):setValue(VSceneBackgroundMusic, "sounds/music/test.ogg")


    7281 Posts

  • #5, by MortoAllegroTuesday, 03. March 2015, 11:48 10 years ago
    Thanks a lot!
    i'll try to figure it out, and i'll try to do things how you suggest.

    "Class explanation?" Sorry i mean, i was a Unity user for two years, and in that Engine there is so many "Class" that give you a fast way to interact with the Engine. And a large Documentation and example for all codes.

    as for the "game.CurrentScene.BackgroundMusic" you mentioned, there is not an example to how to use it.
    on the wiki i can't figure it out if associated there is command like ".getMusic" or .PlayinLoop() property or even more..

    ok the Engine is build in LUA, but people need a way to access and interact with Visionaire object too..

    maybe is me, but on visionaire wiki i don't see something like that. Not for all object you can acces via script.

    Sorry i don't want to being polemic or something like that ^^


    44 Posts

  • #6, by gustyTuesday, 03. March 2015, 11:53 10 years ago
    i was a Unity user for two years
    Why did you go away from Unity? I heard there is unity toolkit specially for adventure games - AdventureCreator..

    Forum Fan

    159 Posts

  • #7, by MortoAllegroTuesday, 03. March 2015, 12:27 10 years ago
    because that is not suited to pixel art...
    there is a bug that when you have the camera following character with "pixel nearest neighbor" compression attached ,you'll see some strange vertical Flickering at video.
    people on forum say is about sub-pixel futures or something like that.

    Adventure Creator is good for 2.5d like runaway was or for a complete 3d games.

    Visionaire is ok for me, what i was trying to saying before, is not that Unity is better than visionaire, but that i can't figure it out how to interact with it like i was able to do with java or c# in unity.

    what i notice is there is not a very good documentation on the wiki, but as i say before is only my opinion. maybe is me.

    some times i have to post only to obtain a method like you mentioned before.

    People on the Visionaire forum are good and fast like you to answer your query.


    44 Posts

  • #8, by MortoAllegroTuesday, 03. March 2015, 12:57 10 years ago
    by the way according to what you say i use visionaire to do this:

    i have on a scene an Action that i have called "PlayRandom" that i call at the beginning of the scene.

    - set random value in bg_music between 1 and 3
    - pause for 500 milliseconds
    - if value bg_music = 1
    Play sound "song01"
    wait until finish
    pause for 60 sec
    call action "playRandom"
    end if
    - if value bg_music = 2
    Play sound "song02"
    wait until finish
    pause for 60 sec
    call action "playRandom"
    end if
    - if value bg_music = 3
    pause for 60 sec
    call action "playRandom"
    end if

    but when the game start set random works fine, but when the code recall himself the value appear to be the same.(if it play song one, than he play that song in loop)

    its seems that value random dosen't refresh itself

    set random value does not refresh itself when i recall the script?

    what i doing wrong?


    44 Posts

  • #9, by afrlmeTuesday, 03. March 2015, 13:15 10 years ago
    Hmm the Visionaire Studio is built with C++, however it contains a object model which is stored inside of what we call the data structure. Most things can be accessed / manipulated via Lua script.

    I believe C is also allowed - well at least it is in regards to creating openGL shader effects.

    Now... Visionaire Studio was never intended to be fully scriptable, hence not everything can be scripted, accessed or manipulated via Lua script. There are no classes, like c# / java style code of unity or certain other engines, there are the data structure tables & fields & there are exclusive functions that have been implemented by the VS studio team & then there are scripts & workflow functions that I & other people have written.

    Currently the Lua sound functions are separate from the in-editor sounds. It is entirely possible to create, control & manipulate all of your audio via Lua script though, using the Lua functions created for the openAL sound engine that was implemented for cross-platform purposes into Visionaire Studio 4.x.

    Please see the scripting section of the wiki, in particular, these pages:

    1. scripting: introduction to scripting in Visionaire Studio.
    2. player functions: exclusive Lua functions for accessing / manipulating certain features of Visionaire Studio.
    3. data structure: a list of data structure fields & tables, with explanations of what they are for.
    4. script index: a compiled list of scripts, functions, visionaire functions & workflow functions, etc. written by myself & other members.

    P.S: all of the Lua audio functions can be found in the player functions page. I believe nearly all of the function pages contain working examples.

    P.P.S: in regards to the script snippets I provided in my last message: you could add them into an execute a script action part, or maybe include them into a function inside of a definition script or maybe into a executed (non-definition) script - non-definition scripts will only be executed when you call them with the call script action part. Definition scripts will be executed on game launch & are useful for defining functions & variables at game launch, which can then be accessed & manipulated from anywhere in the project via execute a script action parts providing the variables, tables & functions are not defined as local.


    7281 Posts

  • #10, by MortoAllegroTuesday, 03. March 2015, 14:20 10 years ago
    As i post before.. i'll try to do that inside visionaire without lua scripting.
    and in the first place the Action i have made, works fine.
    i suppose, i create a loop in that action-part, but in that loop as i say, its seems that "value random" doesn't refresh itself when i recall the Action..

    if at the first run, the value as setted like = 1

    when action recall itself that value still remain the same, as the result are a loop of that sound..


    44 Posts

  • #11, by afrlmeTuesday, 03. March 2015, 14:59 10 years ago
    hmm? If you trigger set random value between x & y then it should change to another value, although there is a chance that it will return the same value. The larger the difference the less chance there will be of getting the same number again.

    You can also use Lua script to set a random number to a value too...
    Values["test"].Int = math.random(10) -- this would set a random value between 1 & 10 to value 'test'

    Feel free to combine scripting & action parts. It's entirely possible because of the execute a script action parts or the call script action parts.

    A loop? for?


    7281 Posts