Thread:Sylvandyr/@comment-5123071-20130929091230/@comment-4830404-20130929163204

Hi there,

MediaWiki/Wikia is really annoying to have to tiptoe around, and random things that work perfectly in other places won't work here.

First off, I suggest putting ALL of your global variables in your MediaWiki data file; don't put any global variables in your .js file. MediaWiki caches .js files aggressively, but not data files, and thus it's easy to update data with ?action=purge on the page, but any updates to .js files require a client side cache clear (and it's hard to get everyone to clear their cache even if you leave a big bold message on the page; someone won't read it). Sticky caching may also occur depending on how uncooperative your browser likes to be; I usually have to use CTRL + Shift + R instead of CTRL + F5 to make sure the cache really really clears so that I can see the effects of my changes.

Second, do not put "var" in front of your global variables. MediaWiki will kill it. I don't know why there's a scoping issue with it, but it simply won't work. Do it like you have it in your data, don't put "var" in front. If you pull up the error console on your wiki page for Sandbox and press Button, it'll tell you arrHead is undefined. Removing the var should fix that (and I seriously suggest moving it to your data file).

Another issue is that you can't inject structures onto the page via code and expect them to be locatable via getElementById. You're throwing some getElemenyById errors whenever you load Sandbox and Sandbox2 (although I suspect it's probably those global var ids that you need to remove the "var" from when declaring).

Anyway, in the case that removing the var doesn't fix it, you need to be aware that the structurs MUST BE DECLARED DIRECTLY ON THE PAGE if you want to access them via getElementById. You can do this via the tags with the MediaWiki files that you've got set up already. This means that with MediaWiki, you cannot type into the code to create an element with a particular id and expect to be able to access that element by looking for it via id. You can still create elements via code (my Breeding Calculator tables are generated by code), but you just don't try to access them later because you can't.

One other thing you should know is that there are often some evil race condition weirdnesses with MediaWiki. If you want to make a javascript prototype object and call one of its functions, you *cannot* do this in the initial onload callstack. You can do it anytime outside of that stack, but if you call any javascript prototype function within your onload stack, it will say that the function doesn't exist. You can create a javascript prototype object in the initial callstack, but you can't call any prototype functions (this includes calling its own functions inside its constructor). Again, it's got some stupid thing to do with the order in which MediaWiki loads things upon startup, and we've got no control over that. I've asked for answers but never received a response from MediaWiki; I've had to do workarounds for it. My setMenuOptions function for the Breeding Calculator runs into that issue, for example, so I had to insert extra code in there.