I've got four problems at the moment so I'm wondering if any of you guys could help me out? I've rolled them all up into one so I'm not posting a load of threads.
I'm working on something in Twine with a friend's son who is 12 (I'm a kind of mentor to him as his dad has done a runner and he looks up to me), and we're doing it as a collaborative effort as we're both working on the story and the code together. The story is typical zombie type stuff inspired by an online game called
Urban Dead - I did post a question about this a while back and since then Matty has jumped on board with ideas etc. To add to the immersion of the game Matty wants to add stuff like e-mails that give hints (which will be received when you scan a character or system in the game) as well as spam e-mails and silly e-mails that will randomly appear and also have accessible links to spoof webpages, and can be accessed via a PDA in the game (if you've ever played Doom 3 or GTA V you'll get the idea).
Now in order to keep a list of the e-mails received there'll be an array called $emailid and each element (is that the right word?) will have a numeric value. There is also another variable ($received) which will keep track of the number of e-mails 'received'. When you access the system the code will look up the number of e-mails which have been received and then run a
FOR simulation loop and step through each element of the array and match up the numeric value to a list in a 'module' and generate the list of e-mail 'subject lines' complete with links to corresponding passages which will have the e-mails in them. This will basically be a variable ($emaillist) with the list in it which is <<print>>ed onto the screen at the time. There'll also be a similar system in place for journal entries for various characters as well which will operate along the same principles.
Now here's the real problem. I'm not all that hot with Javascript and while I
could do it I'd rather not because Matty also has short term memory problems. He's getting to grips with Twine pretty well, but I'd rather not throw in Javascript because then he has the potential to get the two confused and we'd spend more time debugging stuff he's got muddled up than actually doing anything productive. Is there a simpler way of working this out as opposed to the way I've decided we should proceed, that is written purely in Twine (as in FOR loops being supported in 1.4.1 - I did try a few days ago and got an error when I tried to do it, although I can't remember the code I used as I dumped it when it didn't work)?
The second problem is more about SugarCube's save feature. Matty also came up with the idea of making the game 'extendable'. He wants to release content periodically for it in terms of extending the story and I'm wondering if someone used the save feature in SugarCube would the save system still work if the story was expanded at a later date. The original story would be used and then we'd just bolt on the extra stuff to the .tws file, so variables etc would be the same although some new ones would inevitably be introduced for extra features (for instance if the PDA had a Pearborg update and we introduced new features to it).
Thirdly, does SugarCube pre-load images and sounds/music. I'm using Leon's sound macro for the sounds and music which will be a necessity as we've got an idea for a puzzle later on in the game (although we may drop it due to accessibility issues if a player is deaf). As we want the game to be playable on almost all devices (including mobile phones), ideally I don't want the game to end up pre-loading all the resources used and either hitting a point where it runs out of memory and/or crashes the device. I've got no problem with streaming or loading the audio on demand, but considering all the files will be 320Kbps MP3s and equivalents they'll be quite hefty and come along with a warning that unless you have an AYCE dataplan on mobile devices then stick to wifi. If it does pre-load the images is there any way to turn it off? I apologise if I've missed something in the SugarCube documentation that mentions this.
Lastly, and this is to do with Leon's sound macro. As I understand it, the sound files need to be converted to different formats to be compatible with certain browsers. If I created a variable called $ound for instance and then used
<<set $ound = "somesound">>
<<playsound $ound >>
would it look through the extensions for that particular browser or would it need me to actually write some code to get the browser version? I'm asking because in the macro there's a section that has...
var div = document.getElementById("store-area").firstChild;
var fe = ["ogg", "mp3", "wav", "webm"];
while (div) {
var b = String.fromCharCode(92);
var q = '"';
var re = "['" + q + "]([^" + q + "']*?)" + b + ".(ogg|mp3|wav|webm)['" + q + "]";
k(new RegExp(re, "gi"));
div = div.nextSibling;
}
...and if I'm reading it right it goes through the various extensions and then sees which one plays in relation to the browser. Am I correct in thinking that as long as I supply the correct file name, it will just go through and see which extension it needs? I would test it myself, but I only have access to Firefox, Palemoon (a FF variant) and Chrome and they all worked with .mp3 extensions, although another machine I use has Dragon and IceDragon (Comodo's version of Chrome and Firefox respectively) and nothing worked sound wise on that.
As always, many thanks for reading and more thanks if you can help me out
Comments
It's using twee notation, so the name with the colon is the name of the passage the following code goes into. All the macro should be nobr passages. The only painful bit is the inbox which needs a listEmail call for each possible email. StoryInit is an initializer passage.
Mik
Wait. You talk about using a simulated loop (via recursive
<<display>>
of a Twine passage), but then seem to say that's too "JavaScript" for you? I must have misunderstood that somewhere. Clarify, please?Provisionally, yes. As long as you keep the StoryTitle the same, then you can load the same saves no matter how many times you tweak or add content to the game. That said, you won't necessarily be able to access new content with any save depending on how you structure the new content. For example, a player burns down the old mansion on the hill and creates a save after that point, and then you later expand the mansion will additional content, that save might not be able to see the new content (because you know, smoking ruins). Make sense?
No. SugarCube itself does no loading (not in the sense you mean anyway). SugarCube does have a "loader" (a glorified loading screen really), but it's only to hide various unpleasantness if the browser is talking a long time to load either the game itself and/or external resources, for whatever reason. All resource loading is left to the browser.
That said, some additional thoughts:
<<playsound>>
, etc.) will scan through the game's passage store and will create an<audio>
element for all audio files that it can find. Unfortunately, what the browser does at that point is entirely left up to it. That can be changed by modifying the<audio>
element creation code to add thepreload
attribute with an appropriate value.The code wants an extension, so you should specify an actual audio file with extension (i.e. "
somesound.mp3
"). And yes, the macros will try to play whatever the browser claims that it can support (regardless of the extension you specify, though it will check the extension first before trying the other types).During startup the macros will attempt to setup an
<audio>
element using the first type that the browser claims it can play. The types are tried in order of: the file's type (based on its extension),ogg
,mp3
,wav
,webm
. So, as long as you provide your audio files in a range of formats (mp3
andogg
would probably suffice), the macros will pick what the browser can play regardless of the specified extension.For example, this code: Will prefer to play
somesound.mp3
, however, if the browser claims that it can only playogg
files, then the macros will attempt to playsomesound.ogg
instead (even though you specified anmp3
).They're using SugarCube, that isn't going to work.
What I actually meant by JavaScript is like the sound script for instance. He can handle stuff like <<display>> or <<print>> (although he doesn't really get what's going on in the background, nor what the difference is really), and if I said to him he needed to modify a script passage (he hasn't got a clue what they do, just to not mess with them) for instance he'd just go into a spin. I've kind of relegated him to idea generation and minor stuff, then when he's in the same place as me I'll show him how to do things, but he needs to be shown and then I need to type up a little summary so it helps refresh his memory. It's hard to explain because you'd need to know Matty and how to do stuff so it actually 'sticks' in his head (due to his aforementioned memory problems).
Yep that makes sense. When he said he wanted DLC (these kids of the XBox generation...), I explained that if we thought of each addition as a chapter then we could work around that, so even if we burned down the mansion in your example we could then turn it into a building site as the mansion is being rebuilt.
We did play around with the idea of embedding images into the actual story because Matty wouldn't have to remember the extension (a mix of PNG and JPG), but decided against it. He's happy enough as long as he can see the extensions in the file name so I've changed the folder on his laptop that he's using for his Twine stories so it has the extensions visible.
The thing with the data plan isn't an issue for me because I've got AYCE, but I was more concerned with any kids he shares the link with in his school. I know some of the parents have their kids on their contracts without AYCE or the kids are on PAYG and I didn't want him getting grief if they suddenly maxed out the data plan and then ended up with billshock or no credit.
somesound.mp3
, however, if the browser claims that it can only playogg
files, then the macros will attempt to playsomesound.ogg
instead (even though you specified anmp3
).That's cool. I can easily convert the files and pop them on my server and I've got a stupid amount of webspace to play with (I think it's around 100GB).
I'm actually having surgery next week that's got a recovery time of at least four months so I think I'll probably spend some of it learning JavaScript properly so I can actually read the code properly and fully understand what's going on in the background.
@Mykael: Thanks for trying to help, but yes, I am using SugarCube unfortunately. I think I've figured out how to do the email system slightly better as I spent this morning looking at what I can do with the arrays (the joys of working from home most of the time I'm not on site lol ;D) and there's a few neat functions I've discovered.