homepage Welcome to WebmasterWorld Guest from 54.204.215.209
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Flash "Doesn't Notice" Variables
Strangest Thing
MartinWeb




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

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?

 

rocknbil




msg:4076748
 3:24 am on Feb 9, 2010 (gmt 0)

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved