Be a Supporter!

Stage - Class variable updating

  • 229 Views
  • 3 Replies
New Topic Respond to this Topic
mikeMarek
mikeMarek
  • Member since: Jan. 24, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Stage - Class variable updating May. 14th, 2011 @ 01:07 PM Reply

Ahoy, fellow Newgrounders! I seem to have a bit of a predicament on this... Maybe you can help?

I'm working on an event engine, something that allows a developer to add a list of boolean values and function references, so that if the boolean is true, it will call said function, and then wait for the next boolean in sequence to be called before moving on...

Some sample code as follows:

var script:Array = [
[n > 3, trace, "trace function called"]
];

It uses a script format that passes to a class which will parse these and call functions. As you can see, the boolean is (n > 3), where n is a variable on the main timeline. I'm having a bit of difficulty where the (n > 3) gets converted into a boolean value as soon as the swf loads, and then won't update to keep checking for the boolean.

I have found one solution to this, and that is to pass the script over to the class in an ENTER_FRAME method, so that it keeps getting updated that way. I find this a bit messy,and would prefer to do all of the "updating" under-the-hood inside of the class, so when reusing this class it will take minimal work and fuss to use.

Would anyone have any suggestions on how to fix this?

I'm trying to make an open-source game engine, so the quicker I get these classes done the quicker I can put this on NG :D

Thanks for anyone who is willing to help, it's always greatly appreciated!!!
-Mike


BBS Signature
mikeMarek
mikeMarek
  • Member since: Jan. 24, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Stage - Class variable updating May. 14th, 2011 @ 01:08 PM Reply

also, for the script format, index [0] is the boolean value needed to be true, index [1] is the function reference to be called, and index [2] is are the parameters that will be passed to the function when called.... thought that may be of use :/

also sorry for the double post....


BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to Stage - Class variable updating May. 14th, 2011 @ 01:33 PM Reply

You'd need to pass a predicate function instead of an expression.

function predicate():Boolean {
    return n > 3;
}

var script:Array = [
[predicate, trace, "trace function called"]
];

Also, you might want to look into writing custom AS3 event dispatchers, instead of what you're doing.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
mikeMarek
mikeMarek
  • Member since: Jan. 24, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Stage - Class variable updating May. 14th, 2011 @ 01:48 PM Reply

Thanks, I'll look into Custom Dispatchers!

As for the predicate function, it ends up in the same outcome; It's because when submitting a script to the class, the class stores that "script" Array into an internal Array for reference - hence no updating...
If only AS3 supported pointers I could have this done in a few seconds XD


BBS Signature