Skip to main content
Inspiring
April 21, 2016
Question

the trace outputs of a variable is different from one class to the main

  • April 21, 2016
  • 1 reply
  • 855 views

this is an rpg game where my character walks around the field and a battle scene randomly comes up and you have to fight the monster.

when the battle scene comes up, my character stops moving and it enters the battle scene. When the battle is finished and i press an okBtn to return to the field, my character is expected to start moving again which worked for a while.  but now it doesnt.  There is an endTheBattle variable which is false the whole game time.

When i press the okBtn, it makes it endTheBattle true for one split second and then becomes false.  When the endTheBattle is true, it re adds the enter frame evnet listener which should make the character move again.  However it doesnt work.  I trace the variable in the main class and i see the 'true' come up.  But when i trace it in my character class which holds the enter frame event listener, it doesnt come up.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 21, 2016

first, you need to make sure the class that needs to 'see' endTheBattle, actually 'sees' it.  then you need to make sure there's just one endTheBattle or, if there's more than one, that they update each other.  use the trace function to confirm.

if endTheBattle is true momentarily and then false, there's probably a loop (eg, enterframe) that's resetting that variable's value.  find all the places that could do that and use trace to pinpoint the problem.

Inspiring
April 21, 2016

Yes I want to make the variable true for one split second ( which happens when I end the battle scene by pressing the okBtn) so it adds the enter frame event listener once.  When it goes back to the field, it restates it as false. 

the main class controls the variable

In my character class there is an enter frame event called "backup" that says

if(endTheBattle == true)

addEventlistener(enterframe, move character);

in this "backup" enter frame event, I traced endTheBattle but the true statement never comes up.  I make a separate enterframe function in the main class and I trace endTheBattLe and it shows up for that split second

kglad
Community Expert
Community Expert
April 21, 2016

you don't have an enterframe event called 'backup'.

you might have an enterframe listener function called backup, if your code looks like;

something.addEventListener(Event.ENTER_FRAME,backup);

function backup(e:Event):void{

.

.

if(endTheBattle){

etc

.

.

}

}

is that what you mean?

if so, in that same class that has the function backup() you are able to trace endTheBattle and it shows true (momentarily), correct?

if so, in backup(), endTheBattle never traces true, correct?

if so, use some text so you can determine which variable your tracing so you can ensure there's a moment when backup is called and endTheBattle is true in our other location.

you might find, your timing is off or, more likely, you'll find you have two different endTheBattle variables. (eg, one may be local to a function).