View Full Version: Nearly Departed

lassie >>In production >>Nearly Departed


<< Prev | Next >>

NigeC- 04-03-2008

WTG John! congrats! 8) You'd be better off sitting on ND 'til shepherd was released anyway, like Matt said it can only make a great game even better

JohnGreenArt- 10-26-2008

So I've finished the artwork for a game I was hired for and I am looking to get back to working on ND when I can. Not long ago I received an e-mail from someone with a solution to a problem with variables I've had. I won't go into length about the deal, but I have a problem with their solution, and I'm wondering if the Flash-savvy here can help. Basically, this is the actionscript I was recommended to add to the data.fla after the #include line to create my own TIMe that checks the value of a variable (so I could have something occur once upon entering a room instead of each time you enter the room): var brenter=false; _root.TIMe.roomCheckBrenter=function() {       if(brenter==false)       {              playSequence('redlightjoke');              brenter=true;       } } The custom TIMe roomCheckBrenter() is then placed in the enter room TIMe queue for the room I want the sequence played in. Anyway, the problem is when I publish the data.fla I get this error: Operator '=' must be followed by an operand referring to the if(brenter==false) line. If I try to play the game, it just loops the loading screen. Anyone know what's wrong with the script? I'm not even at the point where I can tell if it gives me the result I want, I'm stuck at a point where this solution makes the game unplayable.

bigmac- 10-27-2008

John, good to see you! I believe you're getting that error because the "brenter" value was never created within the TIMe namespace. Without doing a full in-flash -*test*-('"), I think the proper code structure would be: _root.TIMe.brenter=false; _root.TIMe.roomCheckBrenter=function() { if(!this.brenter) { playSequence('redlightjoke'); this.brenter=true; } } Oh, and if you ever get one of those ActionScript compiler errors, you'll never make it past the load screen. A compiler error will abort movie publishing, which means that your game will be loading a malformed data structure.

JohnGreenArt- 10-27-2008

Hi, Greg! Thanks. I pasted your code into the fla, and have the roomCheckBrenter TIMe in the enter room queue (ans have a sequence named redlightjoke that consists of a single line of dialog) and I don't get any errors, but also don't get any results. The game plays fine, but when it changes to the room I want the dialog said in, it just doesn't get said. The playSequence works, because if I just use that TIMe the char says the line (though of course says it each time they enter that room). It's not that big a deal, and I suppose I could either just drop the line or have the character say it each time they enter the room.

NigeC- 10-27-2008

theres a more mechanical way.. background image is a swf with 2 frames set as sprite 2, with 2 phases frame 1 has stop(); _root.TIMe.playSequence('redlightjoke'); _root.TIMe.changePhase('yourroom', 'yourbackground', 2); _root.runActions(); big issue if the level takes awhile to load you might enter with the convo running in Gregs script wouldn't you need _root.TIMe.playSequence('redlightjoke'); rather than just playSequence('redlightjoke'); ? Good to hear your still on with the game John :)

JohnGreenArt- 10-30-2008

So the original e-mailer found a solution. This code is put in the _data.fla: var checkA=false; _root.TIMe.brenter = function() { if(checkA==false) { _root.TIMe.playSequence('redlightjoke'); checkA=true; } } and the following TIMe is put in the enter room queue: brenter() It works! So now the question is, say I wanted more variables (checkB, checkC, and so on). They're easy enough to add to the .fla, but how would the brenter() TIMe know which variable to check? For example, if I have the brenter() TIMe in more than one room, and the player could go into any room first, but each calls a different playSequence, won't the brenter() TIMe just play the first sequence whose variable is set to false? Meaning, if the variables in the _data.fla are listed A, B, C, etc. and each room (room A, B, C...) has a brenter() TIMe, but the player goes into room B first, won't it still check variable A and see that it's false and play that sequence? I guess one solution is a custom TIMe for each one, like brentera, brenterb, and so on...

bigmac- 10-30-2008

John, Couple things – first, you really don't need that starting variable declaration ("var checkA=false;"). That is created within the scope of _data, and the function is created in the scope of the TIMe object, so there is no cross-over between the two. While your "checkA==false" -*test*-('") works, what it's really evaluating is that checkA does not exist within the current scope (or: is "undefined") which just so happens to equate to "false" in AS2. So, you could actually get rid of that initial variable declaration, and just use "checkA == undefined" as your function's -*test*-('") (which will -*test*-('") to see if the specified variable does not resolve). Next, you could parametrize the "brenter" function so that it will -*test*-('") against a dynamic value. It would look like this: _root.TIMe.brenter = function(key:String) { if(this[key] == undefined) { _root.TIMe.playSequence('redlightjoke'); this[key] = true; } } So, that will allow you to pass in a value as an argument of the TIMe to be used a the variable key name. Finally, there's one flaw to the plan – these values don't save with a saved game. So, what you should really do is write the attributes onto gamedata. Of course, you don't want to go blindly writing values onto the source structure because it risks overwriting critical fields... so, I believe there should be a node on game data that is specifically designed to store variables. However, I know you've reported before that game vars don't work, which might mean that I forgot to create the source node for it in _data. Either way, let's just make this script bullet-proof so that it creates its own variables node in the event that there is not one present and ready to receive data... _root.TIMe.brenter = function(key:String) { if (_root.gamedata.gameVars == undefined) { _root.gamedata.gameVars = new Object(); } if(_root.gamedata.gameVars[key] == undefined) { _root.TIMe.playSequence('redlightjoke'); _root.gamedata.gameVars[key] = true; } } Give it a shot. Writing these values onto game data should save the variables with the rest of the data.

JohnGreenArt- 10-30-2008

So, in addition to this new code, what should the TIMe command that I use in the game editor be? Should it still just be brenter() or something else? And should I use your code verbatim, or do things (like ) need to be assigned values? Thanks for the help!

bigmac- 11-03-2008

Sorry John, I forgot the API call. You'd call that as: brenter('someVarKey'); Also, you would just use that code verbatim. That is a variable name name for the piece of data that gets passed in as an argument of the function call. In the case of the above call example, would assume the value of "someVarKey" while the function runs.

JohnGreenArt- 11-03-2008

Thanks for all the help, Greg. So the TIMe is: brenter('someVarKey'); where 'someVarKey' can be whatever string I want (eg, 'room1enter', 'room2enter' and so on) and then the coe in the _data.fla will check to see if that variable is defined and if not play whatever sequence I associate with it. Is that basically how it works?

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.