In my game, you have a songbook that you can flip through, and an instrument to play music on. I want it to be that you can flip the pages and then play whichever song is on it; there’s only one song per page. It loops around once you get through the entire book. Examining the pages while the book is open will give you a different description, and so will playing the song.
My first idea was to make two variables, text called “song name” that stores the name of the song, and a number called “song” that increases by 1 whenever the pages are turned, and loops back when they have all been read. However, I’m running into an error with my code, since it can’t tell what the song name should be, no matter if I have quotation marks or not.
Is there a more efficient way to get the effect I want?
A test case:
The song is a number that varies. The song is usually 0.
The song name is some text that varies.
If the song is 0, now the song name is "White Christmas".
Thanks in advance!
I’d use a table.
A song is a kind of value. Some songs are defined by the Table of Songs.
Table of Songs
song writing playing
Happy Birthday "You've seen this one many a time." "Easy enough to play."
Now you can have a variable of type “song”, and you can print “the writing of the current song” or “the playing of the current song”, and increment it to run through the list.
I tried using a table, but I couldn’t figure out a way to print the text – it didn’t seem to detect variants such as “[playing]”, “[playing of current song]”, or “[the playing of the current song]”. I checked the docs, and there didn’t seem to be a way to make it go down one row at a time, then loop when it reaches the end, without displaying more than one page at once. Is there a way I can do that?
For now, I looked back at my code, and noticed my problem; I was using periods instead of semicolons. So I use that for displaying text; it’s unoptimized, but it works.
The way I’m using a table, it defines a kind of value called “song”. So then you can make a variable of this type (“the current song is a song that varies”), increment it (“now the current song is the song after the current song”), and set it back to the first song when it hits the end (“if the current song is The Final Countdown, now the current song is Happy Birthday”).
Since it’s a kind of value, you can also make actions applying to it, letting people “play [song]” if you want.
I recognise that this question has an Inform 7 tag.
However, if your game embraces music, it becomes something more than a purely textual experience.
Have you considered what other technologies exist to support the delivery of your idea?
I’m suggesting web technologies, ie: HTML5, CSS3. Maybe a bit of JS, and a good, reliable server-side language (Python is my favourite).
@Daniel Stelzer: That makes sense, thanks! I’ll try it out soon.
@tundish: I do have some web development skills, and I’ve been using Python and JS for a while, but I want to learn how to use Inform 7. The songbook is only a small part of the game, and I have the rest of it planned out in a way that works with Inform. Thanks for the recommendation, though! I’ve played some fun IF in different formats, such as Bee and Limerick Heist, so I can look into making games in other ways.
I’m inclined to disagree on that particular point. IF systems with server-side processing (like TADS WebUI, ADRIFT WebRunner, Quest 5) are usually not well-regarded due to additional processing lag, the need for a stable internet connection, and overall poor reliability (since someone needs to pay for hosting and you can’t pass that responsibility on to the IF Archive when using server-side stuff). For multimedia-heavy parser IF I’d rather suggest using Vorple with Inform7.
I used the table idea, along with some Cragne Manor source code, for a more efficient solution. It uses a number to identify the page so it can easily increment, and all the text you need exists in the respective row. I trimmed it a bit for the example, but here’s what the code looks like:
The current songbook page is a number which varies. The current songbook page is 1.
Table of Song-Related Text
page song writing playing
1 "White Christmas" "It's a Christmas classic, written with easy-to-follow notation." "It's not even December, but whatever. It's always Christmas for you."
2 "Happy Birthday" "This one exited copyright recently, so they were able to print it in this book." "You play a classic song, to nobody in particular."
[you can add more songs here]
The songbook is an openable container. The description is "It's a collection of songs.".
The pages are part of the songbook. The description is "It's displaying the sheet music for a song called [quotation mark][song in row current songbook page of the Table of Song-Related Text].[quotation mark]".
Instead of examining the pages:
say "[writing in row current songbook page of the Table of Song-Related Text][line break]";
Instead of turning the pages:
increment the current songbook page;
if the current songbook page is greater than the number of rows in the Table of Song-Related Text, now the current songbook page is 1;
say "You turn the pages to a song called [quotation mark][song in row current songbook page of the Table of Song-Related Text].[quotation mark]";
Playing is an action applying to one carried thing. Understand "play [something preferably held]" as playing.
if the noun is not an instrument:
say "You can't play that.";
say "[playing in row current songbook page of the Table of Song-Related Text]";
Thanks for the replies, everyone!