Post by docclox on Jan 22, 2011 11:56:18 GMT -5
OK, here's some code. There are a few changes to the outline I posted before.
First of all, you can't initialise object literals with variable expressions. So o = { x+b : c } is a syntax error. I've got round this by making the string list an array and providing a function to convert to an object. In practical terms, that means you have to use "[" and "]" to delimit the list and "," instead of ":".
Second thing: I've added two more values: REFUSE for when an assistant refuses an order on grounds of principle (I remember reading that the angel wouldn't do evil things, for instance) and NOTFOUND for when something goes wrong and the eventNum isn't found in the object.
I've also added some code to allow for multiple possible responses to the same event. Basically, instead of giving it a string, you provide an array of strings. For instance:
So for the HSE+BORED case one of the options will be randomly chosen. The others work normally.
We can also handle multi-paragraph exchanges. For this use double square brackets:
And that pushes each string into the hopper in turn. (or that's the idea - not tested yet). This is probably a good time to mention that I've included four $variables that get expanded. $player expands into the player name, $assistant into the assistant name, $girl into the girls name, and $item into the item name (if there is one).
And since the "[[" ... "]]" syntax is just an array inside an array, it means you can combine the two:
What follows is the code that supports this: If you're just writing event scripts, you don't need to understand this.
I want to cobble together some testing for that, and then I'll post the tested .as file.
[edit]
One more option: you can use functions in the list too. So
So that would let you test a variable and change the response accordingly, or you could launch a new screen with a mini-game. This isn't really intended for non-coders - it's just there so we can handle odd cases that don't fit in the string list.
First of all, you can't initialise object literals with variable expressions. So o = { x+b : c } is a syntax error. I've got round this by making the string list an array and providing a function to convert to an object. In practical terms, that means you have to use "[" and "]" to delimit the list and "," instead of ":".
Second thing: I've added two more values: REFUSE for when an assistant refuses an order on grounds of principle (I remember reading that the angel wouldn't do evil things, for instance) and NOTFOUND for when something goes wrong and the eventNum isn't found in the object.
I've also added some code to allow for multiple possible responses to the same event. Basically, instead of giving it a string, you provide an array of strings. For instance:
HSE+BORED , [
"Oh what fun! Another wet nellie who needs to be shown which way up to hold a mop. Is this <i>really</i> the best use of my talents?",
"Here, taste this. Burnt water. I recommend keeping this one her back with her legs apart, since that's where her talents clearly lie"
],
HSE+HAPPY_1 , "She is lazy and slapdash, and left to herself, would leave much undone. Fortunately, I find a riding crop makes a wonderful motivator.",
HSE+HAPPY_2 , "The slave left the room clean, even if she did get filthy in the process. Maybe I should go and help her soap down those hard-to-reach places",
HSE+HAPPY_3 , "Not only do my quarters pass the white glove test, but unasked she has scented them with jasmine and lavender, and left a glass of wine waiting at my bedside. She will do.",
So for the HSE+BORED case one of the options will be randomly chosen. The others work normally.
We can also handle multi-paragraph exchanges. For this use double square brackets:
ART+BORED , "She got more paint on herself than elsewhere. If I she would rub her breasts on the canvas, we could at least sell it as abstract art",
ART+HAPPY_1 , "Composition, perspective, light... I wouldn't have it on MY wall, but I've seen worse in galleries.",
ART+HAPPY_2 , "The silly little tart turns out to have quite the good eye. I think it might be worth developing this",
ART+HAPPY_3 , [[
"$assistant: Delightful! Reminds me of the great Ercollai in his Light period. We should organise a showing.",
"$player: The great e-coli?",
"$assistant: Ercolai! The greatest of the renowned Arn-Hijienik school of art.",
"$player: The unhygienic school of art?",
"$assistant: You are <i>such</i> a philistine. I don't know <i>why</i> I put up with you...",
]],
And that pushes each string into the hopper in turn. (or that's the idea - not tested yet). This is probably a good time to mention that I've included four $variables that get expanded. $player expands into the player name, $assistant into the assistant name, $girl into the girls name, and $item into the item name (if there is one).
And since the "[[" ... "]]" syntax is just an array inside an array, it means you can combine the two:
DEH+BORED , "We take bright, vibrant young women, and we break them down until we destroy all trace of personality. Do you ever ask yourself \"why?\"",
DEH+HAPPY_1 , "She's beginning to realise that the important part of her is not the bit between the ears, but betrween the legs. Slowly, we progress.",
DEH+HAPPY_2 , "The silly slut still has this strange idea that she may be a person. But she's startibg to question it. It won't be long now...",
DEH+HAPPY_3 , [
"All that remains is a cunt that once thought it could think. You will find it obedient, without opinions, but anxious to be used",
[
"$assistant: There is nothing finer than this! To take a woman and destroy her selfhood. To make her a thing of obedient meat. Now we can start to rebuild her",
"$player: Didn't I hear you quesioning the point of this, just the other day?",
"$assistant: Darling, if you did, I must have been over-tired. We do this because it is pleasurable, and we do it because we can. What more is there?"
"$player: That's what I like to hear.",
]
],
What follows is the code that supports this: If you're just writing event scripts, you don't need to understand this.
function asLamiaEvents(eventNum):Boolean
{
return assistantEvent(lamiaEvents, eventNum);
}
function assistantEvent(events:Object, eventNum:int)
{
var ret = true;
var s:string;
var eventObj = events[eventNum];
var player_name = get_player_name(); // placeholder - not sure where to fint these
var assistant_name = get_assistant_name(); // likewise
var girl_name = get_girl_name(); // likewise
var item_name = get_item_name(); // likewise
/*
* if the event number isn't found, print the assistants NOTFOUND message
* if THAT isn't found, print a generic message with the name and event number
*/
if(eventObj == null) {
eventObj = events[NOTFOUND];
if(eventObj == null) {
storyHopper.push(assistant_name + " looks confused. She doesn't seem to understand. ("+eventNum+")")
return false;
}
ret = false;
}
/*
* With that settled, there are a few possibilities
*
* the event obj may be:
*
* * A string - to be displayed
* * an array - of alternatives
* * an array of arrays - of alternative multi-part responses
* * a function - to be executed
*
* Ordinarily, I'd say "do the simplest case first,
* but in this case things are a lot simpler if we handle the array cases first
*/
var eventArray = selectEvent(eventObj);
/*
* So now we have an event array. If the original case was a
* string or a function it will be an arrray of one string only.
* otherwise the array will be the inner array selected by selectEvent.
*
* in any case, we need to iterate over that array
*/
for(var i = 0; i < eventArray.length; i++) {
var rc = display_event(eventArray[i]);
if(!rc) {
ret = false;
break;
}
}
return ret;
}
function display_event(ev:Object)
{
/*
* ev shoudl be a function or a string
*/
var typ:string = getQualifiedClassName(ev)
/*
* simplest case: if it's a string just print it
*/
if(typ == "String") {
s = expand(eventObj);
storyHopper.push("<B>" + peopleName(5) + "</b><br>" + wv);
return true;
}
/*
* Next easiest: if it's a function we exectute the function and return the return value.
* This lets us specify events that would be too complicated to fit in the format
*/
if(typ == "Function") {
return eventObj();
}
/*
* Anything else means something went haywire
*/
trace("unexpected type in display_event: " + typ)
return false;
}
function select_event(ev:Object):Array
{
/*
* Our primary task here is this: to detect arrays and to randomly select one element from them
* So first we need to know the type of our parameter object
*/
var typ:string = getQualifiedClassName(ev)
/*
* now - if it's not an array, we wrap it in an array and return it
* that sounds strange, but it will mean that everything that comes back from this function is
* an array we can loop over - even if it only has a single element
*/
if(typ != "Array") {
return [ ev ];
}
/*
* So we DO have an array. We need a random numbe between 0 and the length of the the array.
*/
var index = math.floor(math.random() * ev.length);
/*
* replace eventObj by its randomly selected member
*/
ev = ev[index];
/*
* now - one possibility here is that ev was an array of arrays.
* if so we return the new array. But we need the type again
*/
typ = getQualifiedClassName(ev);
if(typ == "Array") {
return ev;
}
/*
* otherwise we wrap it in an array again
*/
return [ ev ];
}
I want to cobble together some testing for that, and then I'll post the tested .as file.
[edit]
One more option: you can use functions in the list too. So
BSE+HAPPY_2 , function() {
// anything you like - but you'll need to code it in actionscript
},
BSE+HAPPY_3 , name_of_function_defined_elsewhere,
So that would let you test a variable and change the response accordingly, or you could launch a new screen with a mini-game. This isn't really intended for non-coders - it's just there so we can handle odd cases that don't fit in the string list.