|
Post by zenzou on Feb 6, 2011 15:16:16 GMT -5
- I can't dynamically import .as files, so each girl needs her own #include in the loader module
- There are lots of references to variables named for the girls in other parts of the code. I can create the variables programatically, but if the symbol isn't defined then the compiler sulks and the program won't run.
Is flash able to write to a file? Seems in theory we could have it scan the folders and append anything new it finds to the xml. I guess it's because of my baggage from programing autoit for so long, but I've been thinking of making functions that would form templates to replace repetitive code. One or more lines of code would call the function template, replace a few keywords, and be a viable substitute for say 10 lines of code. Why I bring this up is because if we were to be able to combine some sort of search and write code to find new drag-and-drop files with a general template for making variables for girls that could allow us to do less hard-coding. Was this similar to what you had in mind when you said you could create variables programatically?
|
|
|
Post by docclox on Feb 6, 2011 16:13:51 GMT -5
- I can't dynamically import .as files, so each girl needs her own #include in the loader module
- There are lots of references to variables named for the girls in other parts of the code. I can create the variables programatically, but if the symbol isn't defined then the compiler sulks and the program won't run.
Is flash able to write to a file? Seems in theory we could have it scan the folders and append anything new it finds to the xml. Not really. Flash is heavily sandboxed as a security feature - it's to stop flash apps from scnning your hard drive for credit card numbers and mailing them to blackhatdude.com. If I could have found a way to scan the folder, I probably wouldn't have bothered with the XML. I guess it's because of my baggage from programing autoit for so long, but I've been thinking of making functions that would form templates to replace repetitive code. One or more lines of code would call the function template, replace a few keywords, and be a viable substitute for say 10 lines of code. Why I bring this up is because if we were to be able to combine some sort of search and write code to find new drag-and-drop files with a general template for making variables for girls that could allow us to do less hard-coding. Well, actionscript has good support for anonymous functions and closures, so you can write function generators to do things like that. It's a very cool way of writing templates. Was this similar to what you had in mind when you said you could create variables programatically? Not exactly. loader.as declares this: var menace:MovieClip; Now flash variables are all held as object fields in the parent MovieClip. So saying menace = mc; is the same thing as saying this["menace"] = mc; And in general, I can create a variable called "menace" by assigning to this["menace"] However, in AS3 they've tightened up a lot on variable checking, and flash isn't prepared to just trust that I've created the symbol somewhere or other. So I can create a global called "menace" at run time, but compile time checking means the code won't run. Which is a pain. Workaround is to have an object of movieclips keyed by the girl name, and the create local variables where needed by accessing the value. But that means changing all the girl-specific code, which is why I wanted to talk about it first. [edit] Here's the modified code. This is a pig because it has a copy of the .fla in it for the progress bar clip. Hmmm... could probably have put that in a separate swf too... [edit] would help if I included the download link, I suppose ... www.mediafire.com/?2833ko3cl7fhuxl
|
|
|
Post by daisy_strike on Feb 6, 2011 18:49:49 GMT -5
Still way out of my comfort zone but i was wondering if you could include the include using the actual xml file. Since you already have it build like in Slavemaker... and that's my shot in the dark. I'm not going to be much help here sorry.
Or maybe thats what you had in mind in the first place.
Daisy
|
|
|
Post by docclox on Feb 6, 2011 19:31:46 GMT -5
Still way out of my comfort zone but i was wondering if you could include the include using the actual xml file. Since you already have it build like in Slavemaker... and that's my shot in the dark. I'm not going to be much help here sorry. Well... I can import actionscript as a string from XML, but I don't think I can parse the AS code to flash bytecode. There was an eval statement in flash, but that hasn't worked since as2, and I believe it was crippled prior to that. I'm not really familiar with the slavemaker clode, so I might be misunderstanding you. Now the best way to do this is probably to go the OO route. We can declare a class, Girl, that can be imported by the game, and which can load its data fields from XML. That gets rid of the big object declarations in the .as files and means we can change girl stats without recompiling which has got to be good for debugging. Trouble is, that doesn't let us add code still. So, I'm thinking we can declare the Girl object in the girls/girlname.as files, customise it as necessary, and then add it as a member of the toplevel movieclip from the file. Then, when loaded, we should be able to retrieve the object. We can do this in combination with XML loaded stats, or just declare the stats in the girl's .as file as we do now. The only problem with that is that I haven't tried it yes, and I'm not sure it will work. I'm happy to find out, but I wanted to make sure you're comfortable with the direction I'm considering before I do. Just to summarise: - Use a "GirlClips" object to store the girl's movieclip object, indexe by name
- Create local names from the object where named gobals are currently referenced
- Create a Girl class
- Include girls/girlname.as in girls/girlname.swf as an extra field in the movie clip
- Optionally, load girl data from XML as well.
|
|
|
Post by daisy_strike on Feb 6, 2011 19:55:53 GMT -5
That is a lot of changes. Personally I think it would be a lot easier on everyone if it was done that way in the long term but my concern is much more short term if we are stuck having to rewrite code every where a variable referencing one of the girls variables is called.... that's a huge undertaking.
Going to leave this up to though Docclox. This is way out of what I know how to do. I personally always disliked that the girl.as was required to be compiled into the main game and felt there should have been a way to call them with out having to recompile the main module. But could never quite figure out how to do that. Your way seems much nicer and would help girl developers. Changing a few variables in an XML and then running the game rather then changing a 1/2 dozen lines and compiling the entire game.
But like I said this is up to you, and its a lot of my odd ball code.
Daisy
|
|
|
Post by docclox on Feb 6, 2011 19:59:33 GMT -5
Going to leave this up to though Docclox. This is way out of what I know how to do. I personally always disliked that the girl.as was required to be compiled into the main game and felt there should have been a way to call them with out having to recompile the main module. But could never quite figure out how to do that. Your way seems much nicer and would help girl developers. Changing a few variables in an XML and then running the game rather then changing a 1/2 dozen lines and compiling the entire game. OK. I'll run a few tests and see what works. [edit] OK, we can do it. I created a dead simple flash loader, and in a girls folder another one with a few pics of Emma Frost because ... well, just because, ok? Anyway, in the emma.fla file I include "emma.as" and in that I had this: this.payload = { msg:"this is a message defined in the loaded swf", ival:99 }; I load that from the level above using the same code as in the otherworld loader, and then run this from the complete event: function load_done() { trace("emma = " + emma); trace("emma.payload = " + emma.payload); trace("emma.payload.msg = " + emma.payload.msg); trace("emma.payload.ival = " + emma.payload.ival); } Sure enough emma = [object MainTimeline] emma.payload = [object Object] emma.payload.msg = this is a message defined in the loaded swf emma.payload.ival = 99 So that much works, and it means we can fold the girlname.as files into the corresponding fla files. Which means we don't need to include them in the loader.as file. That just leaves the named movieclip variables. I can't fold them into the swf (didn't think it would work) but a dictionary/object lookup should work just fine. Tomorrow for that, probably. I also tested the loader, but I didn't add enough pics to slow it down enough to tell whether or not it was working. I'll upload the whole lot in a little while so you can see what I'm talking about. [edit] *** whoops - stupid of me - that one is missing the declared "emma" variable. 2 ticks... [edit] This one should work: www.mediafire.com/?zl3e6f91x8a6sue
|
|
|
Post by docclox on Feb 7, 2011 4:44:31 GMT -5
So if we're going to do this, we need a Girl class. Mainly so we can pass back access to the girl-specific functions.
Anyway, first cut of a class definition (bit of a monster, this):
package { public var girlName:String; public var girlArch:String;
public var girlAge:String; public var girlBloodType:String; public var girlCupSize:int; //0 = A, 1= B, 2 = C, 3 = D, 4 = DD, 5 = DDD, 6 = DDDD /* * numebr of a free item a girl gets when created and can't be removed by trainer. * for list go to item.as item number (first number in array) Not Implemented yet... */ public var girlDefaultItem:int; public var girlHeight:int; //unknown metric public var girlWeight:int; //unknown metric public var girlSize1:int; //3 sizes Bust metric cm public var girlSize2:int; //3 sizes Waist metric cm public var girlSize3:int; //3 sizes hips metric cm public var girlBoolean1:Boolean;//used for girl specific events public var girlBoolean2:Boolean;//used for girl specific events public var girlBoolean3:Boolean;//used for girl specific events public var girlBoolean4:Boolean;//used for girl specific events public var girlBoolean5:Boolean;//used for girl specific events public var girlInt1:int; //used for girl specific events public var girlInt2:int; public var girlInt3:int; public var girlInt4:int; public var girlInt5:int; public var girlString:String; //used for girl specific events public var girlItems:Array; public var girlEffect:Array; /* * piercings */ public var girlEPierce:Boolean; // for Archetype public var girlEPiercePer:int; //percentage for non-arch higher is less likely public var girlNPierce:Boolean; //arch public var girlNPiercePer:int; //percentage for non-arch higher is less likely public var girlCPierce:Boolean; //arch public var girlCPiercePer:int; //percentage for non-arch higher is less likely
public var girlVirginPer:int; //percentage for non-arch higher is less likely public var girlPrime:Boolean; public var girlNative:Boolean; //native or not public var girlPrimeAlready:Boolean; //don't change public var girlLesbianPer:int; //odds that non-arch is lesbian lower is less likely public var girlFutanariPer:int; //odds that non-arch is futanari lower is less likely public var girlSexType:int; //arch sex type 1 = straight, 2= lesbian, 3= futa public var girlSpecial1:int; //arch special (check item list for class and numbering) public var girlSpecial2:int; //arch special
public var girlObedience:int; //arch starting Obedience public var girlObedienceTotal:int; //Has to match girlObedience
public var girlNymph:int; //arch starting Nymph public var girlNymphTotal:int; //Has to match girlNymph
public var girlHappiness:int; //arch starting happiness public var girlHappinessTotal:int; //Has to match girlHappiness
public var girlSanity:int; //arch starting sanity public var girlSanityTotal:int; //Has to match girlSanity
public var girlHealth:int; //arch starting health public var girlHealthTotal:int; //Has to match girlHealth
public var girlLust:int; //arch starting lust public var girlLustTotal:int; //Has to match girlLust
public var girlSex1:int; //arch sex 1 starting sex stat public var girlSex1Total:int; //Has to match girlSex1 public var girlSex2:int; //arch sex 2 starting sex stat public var girlSex2Total:int; //Has to match girlSex2 public var girlSex3:int; //arch sex 3 starting sex stat public var girlSex3Total:int; //Has to match girlSex3
public var girlObedienceItem:int; //don't change public var girlNymphItem:int; //don't change public var girlHappinessItem:int; //don't change public var girlSanityItem:int; //don't change public var girlHealthItem:int; //don't change public var girlLustItem:int; //don't change public var girlSex1Item:int; //don't change public var girlSex2Item:int; //don't change public var girlSex3Item:int; //don't change public var girlSexTotal:int; //Don't change
public var girlSpecial11:int; //arch special 11 starting stats public var girlSpecial11Total:int; //Has to match girlSpecial11
public var girlSpecial12:int; //arch special 12 starting stats public var girlSpecial12Total:int; //Has to match girlSpecial12
public var girlSpecial13:int; //arch special 13 starting stats public var girlSpecial13Total:int; //Has to match girlSpecial13
public var girlSpecial21:int; //arch special 21 starting stats public var girlSpecial21Total:int; //Has to match girlSpecial21
public var girlSpecial22:int; //arch special 22 starting stats public var girlSpecial22Total:int; //Has to match girlSpecial22
public var girlSpecial23:int; //arch special 23 starting stats public var girlSpecial23Total:int; //Has to match girlSpecial23
public var girlSpecial1Total:int; //Do not touch public var girlSpecial2Total:int; //Do Not touch public var girlSpecial11Item:int; //Do Not touch public var girlSpecial12Item:int; //Do Not touch public var girlSpecial13Item:int; //Do Not touch public var girlSpecial21Item:int; //Do Not touch public var girlSpecial22Item:int; //Do Not touch public var girlSpecial23Item:int; //Do Not touch
public var girlPassedSkill:Array; public var girlCombatType:String; public var girlPicMini:Object; // need a better type for this public var girlPicMiniNumber:int; // the mini pic number the girl is using public var girlPicMiniTotal:int; // always subtract one total number of mini pics public var girlMorning:int; //Do Not touch public var girlAfternoon:int; //Do Not touch public var girlEvening:int; //Do Not touch public var girlNight:int; //Do Not touch public var girlRoom:Boolean; //Do Not touch public var girlMorningIcon1:int; //Do Not touch public var girlMorningIcon2:int; //Do Not touch public var girlAfternoonIcon1:int; //Do Not touch public var girlAfternoonIcon2:int; //Do Not touch public var girlEveningIcon1:int; //Do Not touch public var girlEveningIcon2:int; //Do Not touch public var girlNightIcon1:int; //Do Not touch public var girlNightIcon2:int; //Do Not touch public class Girl {
public function Girl() { // constructor code }
// WIP!! public function load(file:String, next:Function) { var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, function(e:Event) { var xml:XML = new XML(e.target.data); }); xmlLoader.load(new URLRequest("girls.xml")); }
public function girlPicFunction(pic:int) { } public function girlEventFunction(eventNum:int):Boolean { }
public function girlMakeMiniFuction(item:int):Object { }
public function girlHideFunction() { }
public function girlMiniHideFunction() { } } }
I've kept the field names the same so far as possible, so there shouldn't be any major changes needed to the code that uses this. I'm still debating whether to require a subclass from specific girl implementations, or just to have function refs and call them from the class methods, much as in daisy's original code. I'm leaning toward the function ref approach - easier for girl designers, and we can re-use existing functions with no work. After all, there's nothing to stop a designer creating a subclass if they wish.
Here's some XML for Sheryl (picked because her file is the biggest and I want some load times).
<Girl Name = 'Sheryl' Arch = 'Sheryl' Age = '17' BloodType = 'α'
<!-- !-- Cup Size: 0 = A, 1= B, 2 = C, 3 = D, 4 = DD, 5 = DDD, 6 = DDDD !--> CupSize = '2' girlHeight = '164' <!-- unknown metric --> girlWeight = '55' <!-- unknown metric --> Bust = '34' <!-- size in cm --> Waist = '26' Hips = '37'
EPierceArch = "true" EPiercePercent = '5' <!-- LOW is less likely -->
NPierceArch = "true" NPiercePercent = '5'
CPierceArch = "true" CPiercePercent = '5'
VirginPercent = '20'
Native = 'false'
LesbianPercent = '2' FutanariPercent = '1'
SexTypeArch = 'straight' <!-- options: "straight", "lesbian", "futa" --> <!-- !-- not sure where these numbers are defined. The original comment said to check !-- the item list - which would mean a diamond earing and an amethyst earing. !-- So guess the comment is out of date !--> Special1 = '4' //arch special (check item list for class and numbering) Special2 = '5' <!-- !-- arch starting stats !--> Obedience = '0' Nymph = '20' Happiness = '10' Sanity = '100' Health = '100' Lust = '20' Sex1 = '0' Sex2 = '0' Sex3 = '0' Special11 = '0' Special12 = '0' Special13 = '0' Special21 = '0' Special22 = '0' Special23 = '0'
girlCombatType = "Singer" />
I've removed the "girl" prefix from the fields, since it's kind of redundant here. it still exists in the class, so it's just for designer convenience. I've also taken the liberty of making all the Percents work on the basis of "low is less likely". Again, I'll invert the odds where necessary so the class values are unaffected.
I could use some explanation of Special1 and Special2 - or girlSpecial1 and GirlSpecial2 in the .as file.
In the meantime, I need to finish the class XML loader.
[edit]
I should add that the stuff in the original file marked "don't touch this" I haven't included in the XML format. If it's not to be changed, it doesn't make sense to let people change it in the first place.
|
|
|
Post by daisy_strike on Feb 7, 2011 6:29:21 GMT -5
Special1 and Special2 - or girlSpecial1 and GirlSpecial2 are actually the classes... I don't know why they were called that originally.
Looking really interestingly.
Daisy
|
|
|
Post by docclox on Feb 7, 2011 17:27:01 GMT -5
OK, interesting stuff. I'm going to have problems with functions used in the girl's personal as files, but defined in the rest of the project. It's the same problem in reverse, essentially - we have functions in the larger flash project that aren't linked by the library swf. I think I have a way to use a helper class and sidestep the problem without causing too much disruption. I'll need to try a few more things. Also interesting - when I add actionscript to the Sheryl.fla file, be it only an include to an empty file, I start getting errors like this: Which is weird. The names are the linkage names of the movieclips in the library, so I'm not sure how they can be undefined, nor who is accessing them. I have no idea on this one, but I'll keep digging. [edit] Got it! Needed to import flash.display.MovieClip. [edit] No I don't. Fixes menace (who only had one clip raising the error) but not for Sheryl. Gah! One last thought ... I hadn't fully understood how you're using these girl images. If they're just a pure library, the girl's image movieclip doesn't need to be added to the stage at all. Just find a reference to the one that's needed to display and put that up with addChild when needed, and take it down again when done. Should simplify layering problems, easy memory usage, and get rid of all the girls spamming the screen at load time. OK. Still a way from finding a complete solution, but having fun [edit] About the undefined instance names: www.eddieoneverything.com/flash-9-as3/as3-error-1046-type-was-not-found-or-was-not-a-compile-time-constant.php
|
|
|
Post by docclox on Feb 7, 2011 18:34:18 GMT -5
OK, I think I know the cause: Basically, the names in A and B should be different. It's not a problem if it's just an image bank, but if it's going to have any actionscript, it causes problems. I've changed all the classnames for Sheryl, generally just capitalising the first "S". The class name doesn't matter so much as the instance name in this case. If anyone else finds they need to do this, there's a shortcut - double click on "linkage name" in the library and change it there. Much faster than right-click->properties->change name->click OK
|
|
|
Post by docclox on Feb 8, 2011 5:02:51 GMT -5
OK, so the next problem that needs to be addressed is giving the girl-specific code access to the stuff defined in the game proper. There's a few approaches to that. The cheap and nasty one is probably to say something like this:
var worksafe = root["worksafe"]
or maybe as part of the girl class
class Girl { // ...
private function worksafe() { return root["worksafe"]; } }
That should work since both environments have a root. worksafe won't be defined in the girl's space of course, but then it's never going to be called there, either, so that should be all right.
We can do the same thing for functions, too:
var jobScreenFormat:Function = root["jobScreenFormat"] //... jobScreenFormat(sheryl.sherylbikini)
But that gets a but nasty and risks pulling in half the outside world. What I'd really like to do here is change the girl methods so they return data, and give the caller the job of displaying it. It sounds like a lot of work, but I don't think it needs to be.
For instance, this is the current jobBackground impementation:
function jobBackground(job:int){ hidePersonalJobBackground(); if (job == 2010) { GameArray[whatGirl].girlPicFunction(2000); var temp = talkBackground; } else if (job == 2011) { GameArray[whatGirl].girlPicFunction(2000); var temp = sleepBackground; } else if (job == 2020) { GameArray[whatGirl].girlPicFunction(2000); var temp = crewGuildBackground; } else if (job == 2021) { GameArray[whatGirl].girlPicFunction(2000); var temp = greenClearingBackground; } else if (job == 2040) { GameArray[whatGirl].girlPicFunction(2000); var temp = walkRedLightDistrictBackGround; } else if (job == 2041) { GameArray[whatGirl].girlPicFunction(2000); var temp = townBackground; } else if (job == 2042) { GameArray[whatGirl].girlPicFunction(2000); var temp = greenEdgeBackground; } else if (job == 2043) { GameArray[whatGirl].girlPicFunction(2000); var temp = walkPitEdgeBackground; } else if (job == 2044) { GameArray[whatGirl].girlPicFunction(2000); var temp = walkShrineBackground; } else if (job == 2060) { GameArray[whatGirl].girlPicFunction(2000); var temp = pimpAlleywayBackground; } else if (job == 2300) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2301) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2302) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2310) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2311) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2312) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2313) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2320) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2321) { GameArray[whatGirl].girlPicFunction(2000); } else if (job == 2322) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2323) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2330) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2331) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2332) { GameArray[whatGirl].girlPicFunction(2000); } else if (job == 2340) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2341) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2342) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2350) { GameArray[whatGirl].girlPicFunction(2000); } else if (job == 2351) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2352) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2353) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2354) { GameArray[whatGirl].girlPicFunction(2000); } else if (job == 2355) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2360) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2361) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2370) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2371) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } else if (job == 2372) { GameArray[whatGirl].girlPicFunction(2000); var temp = sexTrainingBackground; } if (temp != null) { jobBackgroundFormat(temp); temp.visible = true; setChildIndex(mainText, numChildren - 1); //setChildIndex(temp, numChildren - 2); setChildIndex(temp, 50); }
Now I reckon we could rewrite that like this:
function code_to_background(job:int):MovieClip { switch(job) { case 2010: return talkBackground; case 2011: return sleepBackground; case 2020: return crewGuildBackground; case 2021: return greenClearingBackground; case 2040: return walkRedLightDistrictBackGround; case 2041: return townBackground; case 2042: return greenEdgeBackground; case 2043: return walkPitEdgeBackground; case 2044: return walkShrineBackground; case 2060: return pimpAlleywayBackground; /* * sex training cases */ case 2300: case 2301: case 2302: case 2310: case 2311: case 2312: case 2313: case 2320: case 2322: case 2323: case 2330: case 2331: case 2340: case 2341: case 2342: case 2351: case 2352: case 2353: case 2355: case 2360: case 2361: case 2370: case 2371: case 2372: return sexTrainingBackground; /* * these had no background, so returning null */ case 2321: case 2332: case 2350: case 2354: return null; default: trace("unhandled job code: " + job); } return null; }
function jobBackground(job:int) { var mc = null; var temp = null; /* * hide the current background */ hidePersonalJobBackground(); /* * get and display the girl image, suitably garbed */ slideShowFormatJob(GameArray[whatGirl].get_job_mc(2000)); /* * look up the job background */ mc = code_to_background(job); /* * if there wasn't one, we're done */ if(mc === null) { return; } /* * set the background */ jobBackgroundFormat(mc); mc.visible = true; setChildIndex(mainText, numChildren - 1); setChildIndex(mc, 50); }
So the girl.get_job_mc() func returns a movieclip reference of the girl. It's the same thing as girlPicFunction(2000) was doing, and probably the same code driving it. Except that now Girl.as doesn't need to know about slideShowFormatJob() and the design is that much cleaner.
Rambling on a bit here - I don't think I'm entirely awake yet. I think a coffee is called for...
|
|
|
Post by daisy_strike on Feb 8, 2011 5:21:34 GMT -5
Your code looks a lot cleaner then mine... I like it. Really should start looking in on how to use switch and case rather then all if statements...
Daisy
|
|
|
Post by docclox on Feb 8, 2011 6:19:12 GMT -5
Your code looks a lot cleaner then mine... I like it. Really should start looking in on how to use switch and case rather then all if statements... I've been doing this sort of thing for a living since the mid 80s. You pick up the odd trick here and there But yeah, switch statements are cool. In general, I always think that if you've got essentially the same block of code repeated a dozen or so times, it's worth taking the time to work out how to separate the data from the code so you can generalise it. Here's a sample implementation of the girl_job_pic() func from the last post. We could also do this by calling SherylPics(2000) ... assuming that SherylPics was modified to return a clip rather than trying to display it, anyway. function SherylJobPic(girl:Girl, clips:MovieClip):MovieClip{ var worksafe = sheryl.worksafe(); /* * what's in the slot for the dress item? * Nothing, not surprisingly, means nude */ if(girl.girlItems[4] == null) { if(worksafe) { return clips.sheryldress3; } return clips.sherylnude3; } var typ:String = girl.dress_class(); /* * we're going to take the classname for the clip in the dress slot * and see if it contains the string "bikini" - case insensitive * * this'll match normal and chain mail bikinis. And if we subsequently * add "DentalFlossBikini" or "AvacoadoDipBikni", it'll match them too */ if(typ.Match(/bikini/i) { return clips.sherylbikini; } /* * I'm not going case insensitive on this one because there's more of a * risk of the Maid substring cropping up in something else. */ if(typ.Match(/Maid/) { return clips.sherylmaid; } return clips.sheryldress3; }
It might also be worth having some funcs like girl.dress() where public function dress():MovieClip { return girlItems[4]; }
Purely so people don't have to remember that "4" means "dress slot"
|
|
|
Post by zenzou on Feb 8, 2011 19:39:11 GMT -5
OOOHHH!!! So that's how it's done. I referenced switch/case a while back in a different thread, but could never get it to work. Now I get it I think... nice to know
|
|
|
Post by docclox on Feb 8, 2011 19:43:37 GMT -5
OOOHHH!!! So that's how it's done. I referenced switch/case a while back in a different thread, but could never get it to work. Now I get it I think... nice to know Only thing to watch out for: if you're not returning from a case, you need to use "break", or else it'll drop through into the next case switch(x) { case 1: s = "one"; break; case 2: s = "two"; break; case 3: s = "three"; // missing "break" - drops through case 4: s = "four"; } trace(s); so the code above works for 1, 2 and 4, but three gets printed as "four" because there's no break statement. Apart from that, it's dead easy to use
|
|