Welcome to WebmasterWorld Guest from 54.159.190.106

Forum Moderators: open

Message Too Old, No Replies

Flash "Doesn't Notice" Variables

Strangest Thing

   
11:04 pm on Feb 8, 2010 (gmt 0)

5+ Year Member



This is the strangest thing that I have ever seen. Has this happened to anyone else?

I'm trying to make a player AI, and I ran into a problem that the script would only run on certain frames.


//Other code above
}
if(right==1||left==1){
//Other Code Below


For some reason, Flash refused to go into this if statement. Then I changed it to this for testing purposes:

//Other code above
}
trace("R"+right+"L"+left);
if(right==1||left==1){
//Other Code Below


After this, it began to work, and when I removed the line it stopped working. Does anyone know why?
3:24 am on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I've read this four times and it makes no sense at all. :-)

I had the second two ideas below first, but realized: I wonder if these are conflicting with keyboard event constants.

if (Key.getCode() == Key.RIGHT) { // move something right }
if (Key.getCode() == Key.LEFT) { move something left }

So first off, try renaming your variables moveLeft and moveRight, see if it makes any difference. I'm probably way off on this one, don't think left and right alone are reserved.

The other random thought in the absence of an answer is it might have to do with timing or scope, somehow. When you trace, it does take a nanosecond or two to write to the output window, which may be just enough delay to populate left and right. If that theory is true, when you remove trace, it's populating left and right "somewhere else" and that doesn't happen until it's passed this frame. This would be especially true if you have "if left == 0 do nothing" somewhere.

The other possibility, and maybe more likely, is a problem of scope. So next question up: what is the context of this code, and it's sister question, where would left and right be populated?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month