Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Pages: [1] 2  All

Author Topic: Question about Game.PlayMusic()  (Read 13171 times)

0 Members and 1 Guest are viewing this topic.

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Question about Game.PlayMusic()
« on: January 29, 2009, 08:12:34 PM »

Hellow! In the menu of my game to make a music  play  I wrote this code:

Game.PlayMusic("music\Aguado.ogg");

on "New game"
{
//to stop the music when the button "New Game" is pressed
  Game.StopMusic("music\Aguado.ogg");
  Game.ChangeScene("scenes\video\video.scene");
  Game.UnloadObject(this);
 
}

And when I write the same code Game.PlayMusic() for another music in the script file of the first scene it doesn't work.
Maybe I'm doing smth wrong cause I'm not a programmist. Help me please?
And is it posible to make a music play just for one scene ?
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Question about Game.PlayMusic()
« Reply #1 on: January 30, 2009, 04:18:41 AM »

Yes, it's possible to make a music play for just one scene.

Where do you first write the code to play your music?  An introductory scene?  Could you post the entire code?

It would help if you would also post the code from your scene.init file for the first scene where you're having trouble.

And the entire code from your new game button.

« Last Edit: January 30, 2009, 04:20:59 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #2 on: January 30, 2009, 02:33:38 PM »

This is the code written in scene_init.script for Menu:

#include "scripts\base.inc"

// here comes the stuff which initializes the scene

actor.Active = false;

//HERE THE MUSIC BEGINS FOR THE FIRST TIME. IT IS SUPOSED TO BE PLAYED IN THE MENU, SAVE GAME and LOAD GAME
Game.PlayMusic("music\Aguado.ogg");

var WinMenu = Game.LoadWindow("interface\system\firstmenu.window");
WinMenu.GoExclusive();
------------------------------------
This is the code for firstmenu.script (I will post only the part responsible for New Game button):

on "New game"
{
 //THE STOPGAME METHOD I USED BECAUSE OTHERWISE THE MUSIC WILL CONTINUE TO PLAY IN THE GAME FIRST SCENE
  Game.StopMusic("music\Aguado.ogg");
  Game.ChangeScene("scenes\video\video.scene");
  Game.UnloadObject(this);
}
-------------------------------
And this is the code written in scene_init.script for the First Scene:

#include "scripts\base.inc"

// here comes the stuff which initializes the scene

actor.SkipTo(400, 400);
actor.Direction = DI_DOWN;
actor.Active = true;

Game.PlayMusic("music\crypt.ogg");
----------------------------------------

The problem is that if I exit from the first scene to menu the music crypt.ogg plays everywhere : in Menu, Load game, Save game. I just don't know how to make it play only for the First Scene so that if I press esc in Save game menu or Main menu or Load menu the music Aguado.ogg will start to play again.
 
« Last Edit: January 30, 2009, 02:36:45 PM by benkovici »
Logged

Iranicus

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 45
  • .. something is wrong ..
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #3 on: January 30, 2009, 04:44:39 PM »

Quote
And is it posible to make a music play just for one scene ?

Yes, of course. You can also use Scene.PlaySound() function with the same parameters as Game.PlayMusic use. It is a simple way :).
Logged
Where is the will, there is the way.

Iranicus

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 45
  • .. something is wrong ..
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #4 on: January 30, 2009, 04:48:55 PM »

Quote
The problem is that if I exit from the first scene to menu the music crypt.ogg plays everywhere : in Menu, Load game, Save game. I just don't know how to make it play only for the First Scene so that if I press esc in Save game menu or Main menu or Load menu the music Aguado.ogg will start to play again.
 

Yes, but it is normal because object Game is something as global variable. If you want to run other music in any scene, window you have to use Game.PlayMusic() again with other music file.
Logged
Where is the will, there is the way.

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #5 on: January 31, 2009, 12:54:17 PM »

[quote/]
Yes, but it is normal because object Game is something as global variable. If you want to run other music in any scene, window you have to use Game.PlayMusic() again with other music file.
[/quote]

Thank you very much for the code Scene.PlaySound() ! I'll try it.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Question about Game.PlayMusic()
« Reply #6 on: January 31, 2009, 01:07:50 PM »

Game.PlayMusic() must work anywhere. If it doesn't, you probably misspelled the filename or something like this.
Also, in your code, Game.StopMusic("music\Aguado.ogg"); is unnecessary. StopMusic() doesn't expect any parameter, it just stops any music currently playing.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #7 on: January 31, 2009, 04:34:13 PM »

Game.PlayMusic() must work anywhere. If it doesn't, you probably misspelled the filename or something like this.
Also, in your code, Game.StopMusic("music\Aguado.ogg"); is unnecessary. StopMusic() doesn't expect any parameter, it just stops any music currently playing.

Thanks Mnemonic I'll keep it in mind but I have another problem and I don't know how to fix it. I'm really stuck.
When I press the button "resume" in my game's menu to go back in game the music for any scene doesn't play though in scene_init.script of each scene is written the code Game.PlayMusic() with a music file attached to it of course. The code for "resume" button is:

on "resume"
{//stops the menu music
  Game.StopMusic("music\Aguado.ogg");
  this.Close();
}
----------------
With save and load game I have the same problem. My save and load script file is the same as in Wintermute's demo_3d game. When the game saved/loaded a scene, it playes Menu's music in that scene but not the music written in scene_init.script of each scene. Help me please!
« Last Edit: January 31, 2009, 04:43:58 PM by benkovici »
Logged

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #8 on: January 31, 2009, 05:45:12 PM »

I'm not sure, but I think Game.StopMusic(); stops all currently playing music. Am I right Mnemonic? You can try using SomeEntity.PlayMusic(xy); in your window or Window.PlaySound(xy); on the window itself.
Logged

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #9 on: February 01, 2009, 12:16:55 PM »

I'm not sure, but I think Game.StopMusic(); stops all currently playing music. Am I right Mnemonic? You can try using SomeEntity.PlayMusic(xy); in your window or Window.PlaySound(xy); on the window itself.

Thanks for help! I'll try this code.
But I think the problem is not so much in music than in Save and load Window. After the game saves/loades a scene it plays not the music that is written in the scene_init.script
of any scene but the music from Menu window. Why this is happening????
I wrote the code Game.PlayMusic("music\Aguado.ogg"); in the Menu script and this music playes in Save game and load game also. That's all right. In the first scene script is attached another music Game.PlayMusic("music\crypt.ogg");
Why then after the game saves or loads, in the first scene  Aguado.ogg is played instead of  crypt.ogg????
Logged

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #10 on: February 01, 2009, 06:49:42 PM »

Do you stop crypt.ogg and play aguado.ogg befor opening your menu window?
If so, you saving aguado.ogg as active music file.
Logged

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #11 on: February 01, 2009, 07:09:35 PM »

Do you stop crypt.ogg and play aguado.ogg befor opening your menu window?
If so, you saving aguado.ogg as active music file.

No. The music aguado.ogg begins because Game.PlayMusic(); is written in the menu code and it starts automatically when I pass to Menu.
When I'm in game (Crypt scene) I press Esc, the Main menu appears. Then I press Save game/Load game. The Save game window appears and when I press on the first slot the game saves and automatically resumes to Crypt scene but the music plays still from menu.  ???

How to make a music play only one time in scene cause it repites by default?

And I have a question about items.
 Lets say I have a book in inventory and I would like that on right click on it, the book to dissapear and another item to appear. Where should I write the code on "RightClick" for this to happen cause I already have a code in book.script for taking the book from floor:

on "RightClick"
{

  actor.GoTo(173, 367);
  actor.TurnTo(DI_UPLEFT);

  Game.Interactive = false;
  actor.Talk("I'll take it.");

  // play "take" animation
  actor.PlayAnim("actors\molly\ul\take1.sprite");

  // hide the book entity and place "book" item into the inventory
  Game.TakeItem("book");
  var EntBook = Scene.GetNode("book");
  EntBook.Active = false;

  // play the second "take" animation
  actor.PlayAnim("actors\molly\ul\take2.sprite");

  Game.Interactive = true;
}
 -----------------------
 And what should I add  in game.script in this line:

on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }

  var ActObj = Game.ActiveObject;
« Last Edit: February 02, 2009, 05:21:03 PM by benkovici »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Question about Game.PlayMusic()
« Reply #12 on: February 02, 2009, 08:06:13 PM »

Please note that scene_init.script is only executed when you ENTER the scene. If you display a menu (by displaying a window) the scene is still running in the background so after closing the menu (or loading the game for that matter) doesn't actually do anything to that scene.

So, you might want to *pause* the music when displaying the menu instead (Game.PauseMusic()), play the menu music in another channel (Game.PlayMusicChannel()) and resume the original music upon leaving the menu (Game.ResumeMusic()).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

benkovici

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Question about Game.PlayMusic()
« Reply #13 on: February 04, 2009, 02:27:54 PM »

Please note that scene_init.script is only executed when you ENTER the scene. If you display a menu (by displaying a window) the scene is still running in the background so after closing the menu (or loading the game for that matter) doesn't actually do anything to that scene.

So, you might want to *pause* the music when displaying the menu instead (Game.PauseMusic()), play the menu music in another channel (Game.PlayMusicChannel()) and resume the original music upon leaving the menu (Game.ResumeMusic()).


Thanks for help Mnemonic!!!!!
I'll try this code.

But could you be so kind to help me in this question about items?

 Lets say I have a book in inventory and I would like that on right click on it, the book to dissapear and another item to appear. Where should I write the code on "RightClick" for this to happen cause I already have a code in book.script for taking the book from floor:

on "RightClick"
{

  actor.GoTo(173, 367);
  actor.TurnTo(DI_UPLEFT);

  Game.Interactive = false;
  actor.Talk("I'll take it.");

  // play "take" animation
  actor.PlayAnim("actors\molly\ul\take1.sprite");

  // hide the book entity and place "book" item into the inventory
  Game.TakeItem("book");
  var EntBook = Scene.GetNode("book");
  EntBook.Active = false;

  // play the second "take" animation
  actor.PlayAnim("actors\molly\ul\take2.sprite");

  Game.Interactive = true;
}
 -----------------------
 And what should I add  in game.script in this line:

on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }

Thanks beforehand!
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Question about Game.PlayMusic()
« Reply #14 on: February 04, 2009, 05:53:53 PM »

If you want to add right click handler for an *inventory* item, look in the "items" folder. The "book" item in inventory is unrelated to the book in scene.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
Pages: [1] 2  All
 

Page created in 0.056 seconds with 25 queries.