start up main menu music?

Scripting questions, discussions, etc
9 posts Page 1 of 1
fLUnKnhaXYU
Posts: 36
Joined: Wed Nov 15, 2017 8:19 am
  by fLUnKnhaXYU » Wed Aug 15, 2018 8:35 am
Hi, where might I place the bit of scripting necessary for playing a music file in the start up main menu ., that will repeat once a mission has been exited . So far it has dumped all of my efforts at the destroy server (ish) . I resolved it by re executing a file with the music profile and play commands after the destroy server , but I havent been quite satified that its a REAL/GOOD way of doing this . Thank You
Duion
Posts: 1082
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Wed Aug 15, 2018 12:03 pm
I display a level at the main menu, which has background music, this works well, but may be a bit over the top just to have music.
fLUnKnhaXYU
Posts: 36
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Thu Aug 16, 2018 4:16 am
Thanks Duion , I have your UberGame and I especially like the main menu , scenes are REAL COOL . Im just going for basic asthetica , if you will , I tried using onMainMenuWake in mainMenu GUI but it seems that the destroyServer , in particular the ,disconnectedCleanup function which has a 1 second wait , the command would execute my music profile resume play but, it seems , that after the 1 second it too was flushed , again I say , it seems to me . So , i scheduled a call to a function which reloads the music profile and plays it at just milliseconds after the disconnectedCleanup runs and it goes well , But it seems "hacky?"

somehere in this file is where i put the schedule to reload and play the music
scripts/client/serverconnection.CS
func disconnectedCleanup

It calls a function which I put in here
./core/scripts/client/client.CS
func mainmenumusic

SO , what do you think ?
Duion
Posts: 1082
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Thu Aug 16, 2018 10:30 am
I have no idea what you are doing. Isn't there a tutorial for playing music in main menu? Otherwise I would just step through the code in debugger and see where the music stops and execute it there.
Steve_Yorkshire
Posts: 293
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Thu Aug 16, 2018 4:19 pm
You'll probably need to init the datablock for the music before all other datablocks are loaded. For Airship Dragoon I had it in scripts/client/init.cs right at the top before anything else is loaded.
datablock SFXProfile("musicloop0") 
{
   filename = "audio/music/musicloop0";
   description = "AudioMusicLoop2D";
   preload = false;
};
And I had it playing on the startup screen with my custom startUpGui.cs onWake(). You should be able to stick this in MainMenuGui.cs onWake().
      if(!$mainTheme)
      {
         echo("\c4create main theme music");
         $mainTheme = sfxCreateSource("musicloop0");
      }
      
      if(!$mainTheme.isPlaying())
         $mainTheme.play();
Also be aware of datablocks getting deleted when the server is killed, as it ends up removing all audio from Guis. I ended up commenting that out for my single player game.
In core/scripts/server/server.cs destroyServer():
   // Delete all the data blocks...
   //deleteDataBlocks();//yorks very much out for SP
Duion
Posts: 1082
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Thu Aug 16, 2018 4:35 pm
Ah yes now I remember, I did stick some scripts into main.cs so it was always executed since scripts or datablocks inside deeper folders usually get deleted or reset on mission ending.
fLUnKnhaXYU
Posts: 36
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Fri Aug 17, 2018 2:48 am
// ./scripts/gui/startup.CS

//--------------------------THIS SECTION SHOWS THE CALL TO PLAY LOGOMUSIC  


function loadStartup()
{
   // The index of the current splash screen
   $StartupIdx = 0;

   // A list of the splash screens and logos
   // to cycle through. Note that they have to
   // be in consecutive numerical order
   StartupGui.bitmap0     = "art/gui/background";
   StartupGui.logo0       = "art/gui/Torque-3D-logo";
   StartupGui.logoPos0    = "178 251";
   StartupGui.logoExtent0 = "443 139";

   // Call the next() function to set our firt
   // splash screen
   StartupGui.next();

   // Play our startup sound
 SFXPlayOnce(AudioGui, "art/sound/gui/logo");//--------PLAY THE LOGOSOUND
//SFXPlay(logosound);
//echo("PLAYING ONCE PLAYINGONCE PLAYING ONCE");

}

//.......................................................

//----------------------------   IN THIS SECTION I WAIT UNTIL AFTER THE 
//----------------------------   LOADMAINMENU() CALL THEN EXECUTE THE FILE
//----------------------------   WITH THE SFXPROFILE DATABLOCK (FIRST TIME)

// ./scripts/gui/startup.CS

function StartupGui::onDone(%this)
{
   // If we have been tagged as done decide if we need
   // to end or cycle to the next one
   if (%this.done)
   {

      // See if we have a valid bitmap for the next screen
      if (getVariable(%this @ ".bitmap" @ $StartupIdx) $= "")
      {
         // Clear our data and load the main menu
         %this.done = true;
         
         // NOTE: Don't ever ever delete yourself during a callback from C++.
         //
         // Deleting the whole gui itself seems a bit excessive, what if we want 
         // to return to the startup gui at a later time?  Any bitmaps set on 
         // the controls should be unloaded automatically if the control is not 
         // awake, if this is not the case then that's what needs to be fixed.
         
         //%this.delete();
         //BlankGui.delete();
         //flushTextureCache();


         loadMainMenu();

//DECIDED TO START MAIN MENU MUSIC FROM HERE ...after the first load of
//the main menu . After leaving a game the server is destroyed so , to
//continue the music is done in scripts/client/serverconnection.CS at
//the end of the disconnectedCleanup func , where I exec this same
//gui_music.cs file .

//echo("!!!!BACK FROM STARTUP LOADMAINMENU FUNC CALL!!!!");

//------------------------------------EXECUTE THE FILE WITH THE MUSIC DATABLOCK
	exec("art/gui/gui_music.CS");
      }
      else
      {
         // We do have a bitmap so cycle to it
         %this.next();
      }
   }
}


//================================================================================
//scripts/client/serverconnection.CS

//--------------------------IN THIS FILE I SCHEDULE A CALL TO THE FUNCTION 
//--------------------------IN  ./core/scripts/client/client.CS "MAINMENUMUSIC.CS" 

function disconnect()
{
   // We need to stop the client side simulation
   // else physics resources will not cleanup properly.
   physicsStopSimulation( "client" );

   // Delete the connection if it's still there.
   if (isObject(ServerConnection))
      ServerConnection.delete();
      
   disconnectedCleanup();

   // Call destroyServer in case we're hosting
   destroyServer();
}

function disconnectedCleanup()
{
   // End mission, if it's running.
   
   if( $Client::missionRunning )
      clientEndMission();
      
   // Disable mission lighting if it's going, this is here
   // in case we're disconnected while the mission is loading.
   
   $lightingMission = false;
   $sceneLighting::terminateLighting = true;
   
   // Clear misc script stuff
   HudMessageVector.clear();
   
   //
   LagIcon.setVisible(false);
   PlayerListGui.clear();
   
   // Clear all print messages
   clientCmdclearBottomPrint();
   clientCmdClearCenterPrint();

   // Back to the launch screen
   if (isObject( MainMenuGui ))
      Canvas.setContent( MainMenuGui );

   // Before we destroy the client physics world
   // make sure all ServerConnection objects are deleted.
   if(isObject(ServerConnection))
   {
      ServerConnection.deleteAllObjects();
   }
   
   // We can now delete the client physics simulation.
   physicsDestroyWorld( "client" );

echo("!!!!THIS IS SCRIPTS/CLIENT/SERVERCONNECTION.CS!!!!");
schedule(1, 0 , "mainmenumusic");//-----------I PUT IT HERE , AFTER ALL HAS BEEN DONE
                                 //-------------LESS THAN 1 MILLISECOND DIDNT WORK
                                 //-------------EXECUTES EVERY TIME I END A MISSION

}


//===================================================================================
// ./core/scripts/client/client.CS

//----------------------------------------------------------THIS IS MY NEATO FUNCTION

function mainmenumusic()
{

echo("!!!!THIS IS THE CORE CLIENT MAINMENUMUSIC FUNCTION!!!!");
exec("art/gui/gui_music.cs");

}


//===============================================================
// ./art/gui/GUImusic.CS

//-----------------------THE FILE WITH THE SFXPROFILE DATABLOCKS

//datablock SFXProfile(logoSound)
//{
//   filename = "art/sound/gui/logo.ogg";
//   description = Audiomusic/Loop2d;
//};

datablock SFXProfile(mainMenuMusic)
{
	preload = "0";
   description = Audiomusicloop2d;
   filename = "./gui_music/mainMenu.ogg";
};

echo("!!!!READING THE MUSIC FILE MAINMENUMUSIC!!!!");

sfxplay(mainMenuMusic);

echo("!!!!DID IT PLAY?!!!!");//----of course , quite often this answer was NOOOOOO!!!:)


//======================================================================================

// ./scripts/server/gameCore.CS 

//----------------------------------- I THINK THIS IS THE 1 SECOND DELAY IN THE EXECUTION OF THE 
//----------------------------------- DISCONNECT CLEANUP .

function GameCore::cycleGame(%game)
{
   if (%game.allowCycling)
   {
      // Cycle to the next mission
      cycleGame();
   }
   else
   {
      // We're done with the whole game
      endMission();
      
      // Destroy server to remove all connected clients after they've seen the
      // end game GUI.
      schedule($Game::EndGamePause * 1000, 0, "gameCoreDestroyServer", $Server::Session);// --HERE 
   }
}

//=======================================================================================


So , as the bits concerning single player vs multiplayer , are concerning , .... :?:
I've re-read this a couple of times so i hope i haven't left any cursing in my comments :cry:
Really , I dug around quite hard for this so , if you get a chukkle , how about share it with me .
and thank you both for your responses .
Steve_Yorkshire
Posts: 293
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Fri Aug 17, 2018 6:12 pm
In a multiplayer server, Datablocks get deleted so that the client can then accept new ones from the next server/mission file and then overwrite with new ones. Unfortunately this means client based ones also get deleted on localClientConnection.

As for music:
Exec the datablock before everything else in scripts/client/init.cs":
datablock SFXProfile("musicloop0") 
{
   filename = "audio/music/musicloop0";
   description = "AudioMusicLoop2D";
   preload = false;
};

function initClient()
{
   echo("\n--------- Initializing " @ $appName @ ": Client Scripts ---------");
   //...etc etc
In scripts/gui/startupGui.cs:
function StartupGui::onWake(%this)
{
      if(!$mainTheme)
      {
         echo("\c4create main theme music");
         $mainTheme = sfxCreateSource("musicloop0");
      }
      
      if(!$mainTheme.isPlaying())
         $mainTheme.play();

   $enableDirectInput = "1";
   activateDirectInput();
}
fLUnKnhaXYU
Posts: 36
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Sat Aug 18, 2018 4:05 am
thanks Steve , I'll think about that .
9 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest