Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> [GML] Easy Music Import System, bgm_init();
Zinx10
post Nov 20 2012, 06:12 PM
Post #1


Master of Darkness
Group Icon

Group: Revolutionary
Posts: 1,196
Type: Developer
RM Skill: Advanced
Rev Points: 5






This is a system I have been making. It does all the hard and tedious work for you. All you have to do is put your files within the music folder like so:

Also, you should note how the directory is. It should go like this:
(BEGIN) working_directory => music => Game Name => bgm (END)

The hardest part is making a persistent object called "bgm" which has a create event of this:
Create Event Code (bgm)
global.gameName = 'log_engine';
bgm_init('.mp3', '3', 'true');



CODE
/*
CREDIT:
Torigara - Made File Detection System
Zinx - Made Sound Creation System & Edited File Detection System

HOW TO WORK:
bgm_init(file extension (string), music play type, preload (boolean));

WHAT EACH ARGUMENT MEANS:
File Extension = That is the ending of a file.  It is recommended to use either '.mp3' or '.mid' for the argument.
Music Play Type = The type of music it plays. '0' = Normal Sound, '1' = Background Music, '2' = 3D Sound, '3' = Use Multimedia Player
Preload = Whether the music should be preloaded or not.  'true' = Preload, 'false' = Don't Preload

NON-ARGUMENT VARIABLES YOU NEED:
global.gameName = The name of the game.  For example, I use "log_engine"

NON-ARGUMENT OBJECTS YOU NEED:
bgm = This object is for the music.  It is recommended to have the object be persistent.  This will hold all the music variables.

HOW THE FOLDER SYSTEM WORKS:
(BEGIN) working_directory => music => global.gameName => bgm (END)

HOW TO USE THE MUSIC:
To use the music, do the following code:
sound_play(bgm.songName);
Simply replace 'songName' to the song's name in the folder.

*/

var file_name;
global.file_count = 0;
file_name = file_find_first(working_directory + "\music\" + global.gameName + "\bgm\*" + argument0, 0);
while (file_name != "") {
    global.files[global.file_count] = working_directory + "\" + file_name;
    global.file_count += 1;
    file_name = file_find_next();
}
file_find_close();



i = 0;

while(i != global.file_count){
    string_start_pos = (string_length(working_directory) + 2);
    substring = string_copy(global.files[i], string_start_pos, (string_length(global.files[i]) - (string_start_pos + (string_length(argument0) - 1))));
    execute_string(substring + " = sound_add('music/" + global.gameName + "/bgm/" + substring + argument0 + "', " + argument1 + ", " + argument2 + ");");
    i += 1;
}


Here is an example of how to use it:
Sound Play Code
sound_play(bgm.level_2);

That is all you have to do. Simple, right?

This post has been edited by Zinx10: Nov 21 2012, 01:47 PM


__________________________
My Games
Phelxyre: Time Unbound (Current Project)
Game Thread
A game where you start in the future, but you go to the past, to make things right, hopefully.

The Hidden World
Game Thread
An Arcade-style game where you must go through various puzzles to see if you go home.

Here are all the things I Support (They Include Links!)




Go to the top of the page
 
+Quote Post
   

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 03:09 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker