Bit Blot Forum

Aquaria => Modding => Topic started by: Edwards on January 10, 2009, 08:13:48 am

Title: Guide to Creating New Songs
Post by: Edwards on January 10, 2009, 08:13:48 am
This stuff is currently all over a couple other threads, but I figured it might be a good idea to put it all in one place, nicely labelled, in case of future forum searches (Hi there, future mod-makers! :P ). [EDIT] I guess pinning it would also work.  Thanks!

- Edwards


Guide to Creating New Songs
To create a new song, you will need three files:
1) An xml file, named "songs.xml", which will contain the notes and other non-scripting information for your song.
2) A lua script, named "songs.lua", which will contain the scripts for all new songs you have.
3) An image file, which will contain the symbol to show up when the song is sung.


Part I: songs.xml

The file should be placed directly in the scripts folder of your mod.  If you wish to see an example of a songs.xml file, one is located in the "data" subfolder of the game's data folder.  The file has a very simple structure: it consists of a series of Song tags, each of which is formatted as detailed below:

Format of a Song tag:
<Song idx="1" vox="Naija_Song_EnergyForm" slot="2" name="Energy Form" notes="7 6 5" script="0"/>



Part II: songs.lua

This file should be placed directly in the scripts folder of your mod.  It should contain a function called castSong(), which will be called with the idx of the sung song as an argument.  The file can contain as many helper functions as you wish.  Note that it is re-compiled every time a song is sung that calls castSong(), so it likely will not work to try to make the script have persistent variables (I have not tested this, though).

Example of songs.lua:
function castSong(songIdx)
   if songIdx == 100 then
      -- Script for song 100
   elseif songIdx == 101 then
      -- Script for song 101
   end
   -- If song 102 is played, nothing happens
end



Part III: songslot-*.png

This image file should be a 128x128 png image with a transparent background, named songslot-X.png, where X is the number of the slot this image is associated with (so images should be named songslot-1.png, songslot-35.png, etc.).  The file should be placed in the graphics/song directory of your mod.  Once again, be warned that if you attempt to replace the existing songslot images (for slots 0-10), you will need to force the game to reload all of its cached images either by calling reloadTextures() in mod-init.lua, or by adding a Properties tag to your mod's xml file, with the attribute recache="1" (i.e. <Properties recache="1"/>).  Be further warned that if someone loads a saved game for your mod from the main title screen, the images will not be recached (as of version 1.1.1), so you may want to warn players to only load saved games from your mod's title screen.


Part IV: Tips

My suggestion for creating a new song is to simply play around with the note wheel until you find a 3-5 note sequence that sounds good (and is fairly easy to play, if it's a song that the player will be using often), write it down, and then keep going.  When you have a good set of note sequences, check them against the incorrect note behavior listed below, and select a handful that are clearly distinct from each other and whichever of the pre-existing songs you are keeping.

Behaviour of incorrect notes in the song system:
- There can be any number of incorrect notes before the first correct note.
- There can be up to two wrong notes between a pair of consecutive notes.
- There is no limit on the total number of wrong notes allowed.
- The last note must not be wrong.

Priority seems to be placed on the song sung that is closest to correct.  For example, try combining the shield and bind songs in various ways, or the fish and nature forms.  However, I have run into some issues when mod-added songs are similar to the built-in songs, with the built-in song overriding the new song even if it had a wrong note, and the new song did not (note: this may be an index issue instead, or something else entirely- I have not doe detailed testing).  So, when designing your songs, try to ensure that as few as possible end on the same note (especially the same last note as a built-in song), and if they do end on the same note, make sure that the preceding few notes have as little in common as possible.
Title: Re: Guide to Creating New Songs
Post by: Alec on January 10, 2009, 01:33:57 pm
Awesome, great work! :)
Title: Re: Guide to Creating New Songs
Post by: Danger Mouse on January 10, 2009, 07:19:08 pm
OUTSTANDING!! THANK YOU!!!

Alec: Can we TAC this one up to the top threads for the Modding section?
Title: Re: Guide to Creating New Songs
Post by: Chibi on January 10, 2009, 10:22:29 pm
Definitely sticky this thread - people who take the effort to consolidate all the information into one post are forum gods.  ;D Good work, Edwards!
Title: Re: Guide to Creating New Songs
Post by: Danger Mouse on January 11, 2009, 12:14:57 am
Thank you Alec, and yes, thank you again Edwards!
Title: Re: Guide to Creating New Songs
Post by: Guy on January 11, 2009, 12:22:50 am
Nice work Edwards :). Have you added this to the wiki? Also, do you know if the SONG entries in entityinclude.lua have any relevance?
Another point about the behaviour of incorrect notes (though it may not be relevant): You can play as many incorrect notes as you like at the start, before playing the correct song.
Title: Re: Guide to Creating New Songs
Post by: Edwards on January 11, 2009, 09:16:10 pm
Nice work Edwards :). Have you added this to the wiki? Also, do you know if the SONG entries in entityinclude.lua have any relevance?
I'll add it to the wiki as soon as I have an internet connection long enough to do so, unless someone beats me to it.  As for the SONG_WHATEVER entries in entityinclude.lua, they're just constants containing the indices of the built-in songs.  No real need to change or add to them, but if you're replacing (not recommended!) or adding several songs, it may be a good idea to do so.  That way, existing scripts will break loudly instead of silently if they refer to a replaced song, and you'll be able to have a mnemonic to remember, rather than a random number.  Unfortunately, my attempts to change entityinclude.lua have only occasionally been reflected in files that reference it.  I haven't worked out exactly what's going on there (it may just be a caching issue), but I'm not recommending this in the guide until I know that entityinclude.lua can be reliably modified.

Another point about the behaviour of incorrect notes (though it may not be relevant): You can play as many incorrect notes as you like at the start, before playing the correct song.
Good point.  That would be relevant in some cases, so I'll add it.

@Everyone: You're welcome.  *bows*

@Alec: Thanks for pinning this!

- Edwards
Title: Re: Guide to Creating New Songs
Post by: ryos on January 12, 2009, 03:39:46 am
Heh, I almost forgot that I still needed to enable uploads. That's done now, and in order to test that it works, I took the liberty of adding these images to the page you made on the Wiki.
Title: Re: Guide to Creating New Songs
Post by: Particlese on January 13, 2009, 12:45:25 am
Thanks a lot, Edwards, and excellent timing.  I was just beginning to experiment with this myself, mostly mimicking the files in the Guert mod and main data folders, but I couldn't get it to work.  Now I have some new stuff to play with.  :)
Title: Re: Guide to Creating New Songs
Post by: Tarami on February 24, 2009, 05:51:59 pm
There's a "bug" (or a hack  :D) related to songs - the one with the highest index will not raise script events. This is probably to hide Anima (the song in Sunken City) from showing up with effects and such. The simple workaround is to add a song to the end with a higher index than anything else;

<Song idx="200" name="placeholder" slot="200" notes="" vox=""/>
Title: Re: Guide to Creating New Songs
Post by: Edwards on February 27, 2009, 07:50:34 am
There's a "bug" (or a hack  :D) related to songs - the one with the highest index will not raise script events. This is probably to hide Anima (the song in Sunken City) from showing up with effects and such. The simple workaround is to add a song to the end with a higher index than anything else;
I cannot replicate that (Mac version 1.1.0).  What version are you using, and can you send me a simple mod that demonstrates the problem?  This would explain the issues I had at one point with certain indices apparently not working, but I can't get the system to break now.

- Edwards
Title: Re: Guide to Creating New Songs
Post by: Tarami on February 27, 2009, 09:36:10 am
I'm running Win 1.1.1, but if it's for the reason I'm assuming it should be across all versions. Of course, I can't be sure it is for this exact reason; this is just the way it appears to me and the workaround I suggested above works (for me.)  :)

I'll investigate and post what I find, code if  I can reproduce the bug.
Title: Re: Guide to Creating New Songs
Post by: calebj on November 17, 2009, 02:41:42 am
This is great, very helpful.  I want to make a song where it reloads the current map (I can get it to load a specific map).  Is there a code for getting the current map?  It would be helpful to have in a mod if you got to a place where you were stuck and didn't want to go through the whole dying sequence.
Title: Re: Guide to Creating New Songs
Post by: Kasofa on December 02, 2009, 01:57:29 am
Very good work, thanks for consolidating this, Edwards! If you're who I think you are, I'm pretty sure I saw you on the ASW forums.
Mainly hacking SKF4KA and EV Nova.
Impressive, I must say.

-K
Title: Re: Guide to Creating New Songs
Post by: Edwards on December 20, 2009, 09:07:12 pm
Sorry abut not noticing these posts for a couple of months- I was completely swamped with schoolwork until a couple days ago (you really don't want to see what my RSS reader looked like...).

This is great, very helpful.  I want to make a song where it reloads the current map (I can get it to load a specific map).  Is there a code for getting the current map?  It would be helpful to have in a mod if you got to a place where you were stuck and didn't want to go through the whole dying sequence.
I actually use this one a lot when testing new entity scripts:
-- Reload level (debug song)
elseif songIdx == 105 then
    loadMap(getMapName())


Very good work, thanks for consolidating this, Edwards! If you're who I think you are, I'm pretty sure I saw you on the ASW forums.
Mainly hacking SKF4KA and EV Nova.
Impressive, I must say.
Yep, that's me.  *Bows*

- Edwards
Title: Re: Guide to Creating New Songs
Post by: calebj on January 12, 2010, 11:40:44 pm
Thanks Edwards for the script.  I haven't visited the forums in a while...