...
Backport.js v0.1 and above.
Syntax
...
Exactly the same as Adding missing functions.
Parameters
Exactly the same as Adding missing functions.
, Parameters, Return values
Exactly the same as Adding missing functions.
...
Code Block |
---|
// Warzone 3.1 Beta 1 had a bug in pickStructLocation()
// see http://forums.wz2100.net/viewtopic.php?f=35&t=8694 for details
// Let's fix that bug...
(function() {
// We can work out if this bug is present by checking whether removeReticuleButton() is present
// removeReticuleButton() was added to the JS API in the same version that the pickStructLocation() bug was fixed
if (!backport.global.removeReticuleButton) { // the pickStructLocation() bug is present
// define a new function that calls the original function then fixes it's return value
backport("pickStructLocation",function(droid,structureType,x,y) {
// apply the original (native) function
var pos = pickStructLocation.native.apply(null,arguments);
// the bug effected everything except cyborg factories
if (structureType != "A0CyborgFactory") {
pos.x += 1;
pos.y += 1;
}
// return correct position back to calling script
return pos;
});
}
})();
// thereafter, scripts can safely use pickStructLocation() without having to worry about offset bugs :) |
You can get the pickStructLocation bugfix in a ready-made backport script: pickStructLocation.js
See also
- Adding missing constants – most functions will rely on constants so need to make sure they are around
- Adding missing functions – how to add functions in cases where the native function doesn't exist
- How does Backport work? – learn more about what's going on under the hood