Post by docclox on Feb 10, 2011 12:57:21 GMT -5
OK, I'm busy converting Menace for real to the new system.
One issue I'm having is lots of errors like this:
Which I probably mentioned earlier. Basically, when the Menace swf compiles, it wants to access code from the main program. There's a few ways around this, but the simplest is probably to just return the data, and let the caller take care of displaying it and so on. So I ended up writing something like this:
By way of comparison, here's the old version:
So we're no longer calling jobClean, just flagging that it needs to be called, and so forth. Hopefully the format is fairly clear.
The Story class is quite simple:
And that's it. It's going to need to have a few more flags added, but since the girl object can do any needed stat changing locally, it's not as many as you might suppose. What I'm not adding is a func to display all that. Because Story needs to be imported into Menace.as, and if it access main porgram symbols, we're back to square one.
Instead, I'm adding a relatively straightforward func to events.as called storyteller(). Events.as isn't linked at all by menace.as, so it can access all the game globals without penalty:
And that's about as clean as it gets. I'll probably add in the $ expansion variables from the assistant code at some point as well.
Is that easy enough to follow? I think it's about as good a solution as I'm going to find, but there are quick-and-dirty alternatives if we need them.
[edit]
something for the Girl class
So can set any number of archetype quest variables and have them stored in common as part of the Girl class without needing to loop through looking for the archetype to set the flag, and then loop through all the girls to set the flag for each instance of the arch.
[edit again]
The other cool thing we can do with that, is use getters and setters to recreate the old variables.
So girl.girlBoolean1 = true will set the flag for all girls that share the same arch, and all future instances as well. and x = girl.girlBoolean1 will x to the arch value, regardless of which girl instance is used.
One issue I'm having is lots of errors like this:
V:\otherdev\branches\docclox\girls\Menace.as, Line 14 1180: Call to a possibly undefined method jobClean.V:\otherdev\branches\docclox\girls\Menace.as, Line 15 1180: Call to a possibly undefined method slideShowFormatInternal.
V:\otherdev\branches\docclox\girls\Menace.as, Line 15 1120: Access of undefined property talkBackground.
V:\otherdev\branches\docclox\girls\Menace.as, Line 16 1120: Access of undefined property storyHopper.
V:\otherdev\branches\docclox\girls\Menace.as, Line 16 1180: Call to a possibly undefined method peopleName.
Which I probably mentioned earlier. Basically, when the Menace swf compiles, it wants to access code from the main program. There's a few ways around this, but the simplest is probably to just return the data, and let the caller take care of displaying it and so on. So I ended up writing something like this:
girl_object.event_func = function(girl:Girl, eventNum:int):Story
{
if (eventNum == 2010) {
return new Story({
girl : girl,
event_num : eventNum,
clean : true,
background : "talk",
lines : [
{
who : girl.girlName,
what : "Hmmph... do you think you can control me?"
}
],
main_text : [ 12000, 0, 110 ]
})
}
By way of comparison, here's the old version:
function MenaceEvents(eventNum:int):Boolean{ var temp:int = new int();
temp = int(Math.random()*3) + 1;
if (eventNum == 2010) {
jobClean(eventNum);
slideShowFormatInternal(talkBackground);
storyHopper.push("<B>" + peopleName(10) + "</b><br>Hmmph... do you think you can control me?");
mainTextStart(12000, 0, 110);
return true;
}
So we're no longer calling jobClean, just flagging that it needs to be called, and so forth. Hopefully the format is fairly clear.
The Story class is quite simple:
package { import Girl;
public class Story {
public var girl:Girl;
public var event_num:int;
public var job_clean:Boolean;
public var background:String;
public var lines:Array;
public var main_text:Array;
/*
* passing a raw object to a function is a good
* way to implement named parameters
*/
public function Story(args:Object) {
event_num = args.event_num;
girl = args.girl;
clean = args.job_clean;
background = args.background;
lines = args.lines;
main_text = args.main_text;
}
}
}
And that's it. It's going to need to have a few more flags added, but since the girl object can do any needed stat changing locally, it's not as many as you might suppose. What I'm not adding is a func to display all that. Because Story needs to be imported into Menace.as, and if it access main porgram symbols, we're back to square one.
Instead, I'm adding a relatively straightforward func to events.as called storyteller(). Events.as isn't linked at all by menace.as, so it can access all the game globals without penalty:
function storyteller(story:Story){
if(story.clean) {
jobClean(story.event_num);
}
/*
* assumption here is that background image foo will always
* be named "fooBackground"
*/
if(story.background) {
slideShowFormatInternal(
root[story.background + "Background"]
);
}
for each (var line:Object in story.lines) {
var msg = "<b> + line.who + "</b><br/>"
msg += line.what;
storyHopper.push(line);
}
if(story.main_text) {
var v = story.main_text;
mainTextStart(v[0], v[1], v[2]);
}
}
And that's about as clean as it gets. I'll probably add in the $ expansion variables from the assistant code at some point as well.
Is that easy enough to follow? I think it's about as good a solution as I'm going to find, but there are quick-and-dirty alternatives if we need them.
[edit]
something for the Girl class
/* * OK. Let's have a replacement for the arch flags used on quests
* static object, so it's the same for all instances of girl
* we'll add objects keyed by arch name, and add arbitrary
* flags and values to that keyed by name
*
* the current girlInt[1-5] girlBoolean[1-5] and girlString
* can keep on under those names, but we can have as many
* variables as we need and give them descriptive names
*/
public static var arch_globals:Object = { };
// ...
public function set_arch_global(key:String, value:Object=null)
{
if(arch_globals[girlArch] == null) {
arch_globals[girlArch] = {};
}
arch_globals[girlArch][key] = value;
}
So can set any number of archetype quest variables and have them stored in common as part of the Girl class without needing to loop through looking for the archetype to set the flag, and then loop through all the girls to set the flag for each instance of the arch.
[edit again]
The other cool thing we can do with that, is use getters and setters to recreate the old variables.
public function get girlBoolean1():Boolean {
return get_arch_global("girlBoolean1");
}
public function get girlBoolean2():Boolean {
return get_arch_global("girlBoolean2");
}
public function get girlBoolean3():Boolean {
return get_arch_global("girlBoolean3");
}
public function get girlBoolean1():Boolean {
return get_arch_global("girlBoolean1");
}
// ...
public function set girlBoolean1(value:Boolean) {
return set_arch_global("girlBoolean1", value);
}
public function set girlBoolean2():Boolean {
return get_arch_global("girlBoolean2"));
}
So girl.girlBoolean1 = true will set the flag for all girls that share the same arch, and all future instances as well. and x = girl.girlBoolean1 will x to the arch value, regardless of which girl instance is used.