Jump to content

Functions Need Alert to Initialize?


Selacius

Recommended Posts

So, I am working on a exploration script using JS, some PHP and also some AJAX. Its coming along quite nicely, however, in order for certain functions to work/display the proper content, I need to have an alert within the function. For example, when the player first loads up the map I want a certain <div> element to display the map title (which is retrieved via ajax). When the alert is not present the title shows as undefined, but with the alert it shows properly. The alert does not have to say anything in particular. In another part of the script, when the player walks over a door, the ajax script is supposed to run and automatically move the player to the new map. With the alert I proceed to the new map immediately, but without it, I have to move the player in order for the script to switch over to the new map.Any ideas?

Link to comment
Share on other sites

It seems that something isn't loaded yet by the time the script runs, and the alert() gives it just enough time to appear.What object does the function require? Most likely you can capture it loading with an event and then run the function.

Link to comment
Share on other sites

The function requires an array which is populated via an AJAX query. It seems there is some delay in the AJAX as the screen appears blank until either the alert goes off, or a key is pressed to signify movement.

Link to comment
Share on other sites

The function requires an array which is populated via an AJAX query. It seems there is some delay in the AJAX as the screen appears blank until either the alert goes off, or a key is pressed to signify movement.
Is the AJAX query asyncrounous? If it is, you must call the function at the onreadystatechange function, not outside of it.
Link to comment
Share on other sites

Haha thanks. I did not even think of that. Works perfectly now. Just have to figure out why my movement script breaks partially when I move to a new map. I can move left and up, but not down and right, right off the start. If I move up, then it lets me move down again, and the same for if I move left then I can move right.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...