Undum writeBefore

I’m having trouble with Undum’s system.write and system.writeBefore methods. They’re suppsed to take an optional second argument, elementSelector. The API says this:

“Simply add a paragraph with an id in your game, then later you can give this id as a selector to write, and the new content will be inserted immediately following that paragraph…”

But that isn’t working for me. If I provide no elementSelector, the paragraph (it’s in an act: property in a Situation) prints correctly, at the bottom of the transcript. But when I add an elementSelector argument, either to system.write or to system.writeBefore, the paragraph fails to print.

I’m putting the elementSelector (and the id) in single quotes, which seems to be the approved method, and Firebug reports no problems with the Javascript code – but the paragraph isn’t displaying.

I’m wondering if the elementSelector functionality doesn’t work when the paragraph element being referenced is hiding inside of a previous system.write(). That would be odd…

For reference, here is my (roughly sketched, at present) Situation. It’s embedded within undum.game.situations, as I’m just starting to edit the Tutorial code.

martastudio: new undum.Situation({ enter: function (character, system, from) { system.write ("<p>Marta's studio was housed in a one-room cabin the same size as John's\ workshop, but somehow she contrived to make it feel a great deal more crowded.\ When he strolled in, <a href='./x-marta' class='once'>Marta</a>\ was leaning forward over a large painting that was stretched\ out flat on her worktable. Her free-form canvases owed something to the Jackson\ Pollack school of drip-and-fling, and something to the pulsing psychedelic light shows of the\ 1960s.</p>\ \ <p id='lightning'>She looked up and grinned crookedly at him. \"Has lightning struck yet?\"</p>\ \"Not yet,\" he admitted. \"Have you had any bright ideas?\"<p>\ <p>They fell to discussing the future of the Ambrosia Center, treading ground they had\ trodden, unfruitfully, for a couple of months now.</p>") }, act: function(character, system, action) { switch (action) { case 'x-marta': system.writeBefore("<p> Marta was large-boned and broad-faced, with fly-away hair as unruly as her\ paintings. Her smock and apron were a riot of paint spatters, and fresh smudges\ daubed her cheeks and nose.</p>", 'lightning'); } } } ),

The manual refers to jQuery selectors, so you need to put a hash mark (#) in front of the id. (The manual should mention about it because there’s no way to know unless you’re already familiar with jQuery.)

system.writeBefore("<p> Marta was large-boned and broad-faced, with fly-away hair as unruly as her\ paintings. Her smock and apron were a riot of paint spatters, and fresh smudges\ daubed her cheeks and nose.</p>", '#lightning');

More accurate would be to say that it takes a CSS selector :wink: jQuery didn’t invent selectors.

Ah, perhaps, but I suspect any jQuery selector is allowed. Anyway you need prior knowledge of CSS selectors to know the syntax :slight_smile:

Thanks, Juhana. I figured it was probably something simple like that. And yes, the manual is quite sketchy. The manual seems to assume that the author already knows Javascript. And while a full-on Javascript tutorial would obviously be out of place, it would be nice if the manual spelled out a few things for people like me, who know a little Javascript but not a whole lot.

I noticed, for instance, that in describing the write and writeBefore methods, the manual doesn’t mention that you need to use system.write and system.writeBefore. Nor does it mention, unless I blinked and missed it, that “system” is not a global value, it’s a local value passed into the function as a parameter, which means, I’m pretty sure, that you can’t use these methods in the code for a SimpleSituation. (Unless there’s a way of doing it that I don’t know about.)

If I end up using Undum for this story (which is entirely possible), maybe afterward I’ll sit down and write an expanded doc. Along the way, I’m sure I’ll have more newbie questions…

This would be AWESOME, Jim.