Something is either wrong with my actionscripting or reasoning or both.
I’ve tried a method that I thought should work just fine and it doesn’t and I’ve tried modifying it numerous times and still can’t get it to work correctly. Oh it works, just not like it’s supposed to.
My intention for this part of the game is this. I have a _root score value. If a user finds secret1, then increase score by 1000 (but ramp it up 10 pts per enterFrame so user can see it going up). If user finds secret2, ramp up score to _root.score + 3000 and then stop (just like secret1, but 3000pts instead of 1000pts). If user finds secret3, etc…
Here is my AS, which is all on a MC:
onClipEvent (load) {
_visible = false;
// onLoad, initialize cpScore as the game score when they entered this
// section of the game, basically, take a snapshot of score at this point.
cpScore0 = _root.score;
// allows function below to run on load.
_root.secretFound=true;
function update_cpScore0() {
// if Secret switch is turned on, take a snapshot of
// the current score (_root.score)
// and then set that number as cpScore0, the updated
// initial score.
// Then quickly turn off Secret switch (this function).
if (_root.secretFound) { // a variable that is set to true if any secret is found
cpScore0 = _root.score;
// cpScore box Tester, a dynamic txtbox so I can see value of cpScore0
_root.cpScoreBx = cpScore0;
}
// stops this function from running until another secret is found
_root.secretFound = false;
}
// runs function onLoad
update_cpScore0();
}
onClipEvent (enterFrame) {
// add 1000 pts for finding secret1
// only if kill variable isn't introduced
if (!_root.swKillBonus && _root.secretwinBonus && (_root.score - cpScore0 < 1000)) {
_root.score+=15;
// when score is increased by 1000, nullify variable,
// then update cpScore variable.
}else if ((_root.score - cpScore0) >= 1000) {
_root.secretwinBonus = null;
update_cpScore0();
// disables further point bonus from this secret
_root.swKillBonus = true;
}
// add 3000 pts for finding secret2
// only if kill variable isn't introduced
if (!_root.scKillBonus && _root.secretcarBonus && (_root.score - cpScore0 < 3000)) {
_root.score+=10;
// when score is increased by 3000, nullify variable,
// then update cpScore variable.
}else if ((_root.score - cpScore0) >= 3000) {
_root.secretcarBonus = null;
update_cpScore0();
// disables further point bonus from this secret
_root.scKillBonus = true;
}
// other secrets........................
}
The problem is that the cpScore0 variable will not properly update to the current _root.score. For example, I get to this section of the game with a current score of 0. I find secret1 and _root.score stops incrementing when it gets to 1500 (supposed to stop at 1000) and the _root.cpScoreBx dynamic txtbox tells me that cpScore0 = 500. Well, according to the conditions I set, 1500-500 = 1000, but it was only supposed to add 1000 but it added 1500. I’m really not sure what’s going on… It just doesn’t seem to be updating the score correctly.
Look, I know this is long (possibly confusing) and not a thread that makes your mouth water, but any attempts to help me with this is appreciated. Forgive me if in some way I have not been clear. I’ve tried to be as clear as possible without being too long-winded…
Later.