Skip to content

JavaScript

NGSpace edited this page Apr 11, 2024 · 16 revisions

Want to use javascript? simple!

Important

Make sure to go into the advanced options tab, enabled javascript and change the compiler type to "js" and make sure your hudder file is valid javascript!

Tip

You'll probably need a basic understanding of programming and JavaScript to understand the following.

Warning

JavaScript gives you almost full contol over performance!

Sections? Functions!

each section has it's own function which must return a string! Example:

function topleft() {
  return "this will appear in the top left section!";
}
function bottomleft() {
  return "this in the bottom left!";
}
function topright() {
  return "this in the top right!";
}
function bottomright() {
  return "this in the bottom right!";
}

The functions will be executed in the following order:

topleft()
bottomleft()
topright()
bottomright()
createElements()

to change the size of a section just make a global variable with the section's name + "scale". Example:

var topleftscale = 2;
var bottomleftscale = 2;
var toprightscale = 2;
var bottomrightscale = 2;

The following builtin functions can be used:

Function Description Return type Notes
log(Any object) Writes to the game console. None
warn(Any object) Writes to the game console. None
error(Any object) Writes to the game console. None
alert(Any object) Sends a message to the player. None
getVal(String variable) Returns the variable with the given name (ex. fps, key_h). Any
getNumber(String variable) Returns the Number variable with the given name. Number
getString(String variable) Returns the String variable with the given name. String
getBoolean(String variable) Returns the Boolean variable with the given name. Boolean
setVal(String variable, Any Object) Sets the variable with the given name to the given object. None
drawItem(String itemid, Number x, Number y, Number scale,) Draws the item with the provided itemid on the provided X, Y positions on screen with the scale provided. None
drawSlot(Number slot, Number x, Number y, Number scale, Boolean showcount) Draws the item from the slot provided on the provided X, Y positions on screen with the scale provided. will also draw durability and item count if showcount is true. None Can be used alongside getVal("selectedslot") to draw the item the player is holding
drawArmor(Number slot, Number x, Number y, Number scale, Boolean showcount) Draws the armor from the slot provided on the provided X, Y positions on screen with the scale provided. will also draw durability if showcount is true. None 0 for boots, 1 for leggings, 2 for chestplate and 3 for helmet
drawOffhand(Number x, Number y, Number scale, Boolean showcount) Draws the item held in the offhand on the provided X, Y positions on screen with the scale provided. will also draw durability and item-count if showcount is true. None
strWidth(String text) Returns the length of the string. Number
drawText(Number x, Number y, String text, Number scale, Number color, Boolean shadow) Draws text on the screen with the provided scale and color. if shadow is true then a shadow will also be drawn regardless of the option selected in hudder's settings. None
compile(String filename, String compilertype) Compiles the file with the specified compilertype (or the javascript compiler if none is specified), returns the compile results and adds the elements created by the file. CompileResult CompileResult has the following properties {String topleft,
String bottomleft,
String topright,
String bottomright,
Number topleftscale,
Number bottomleftscale,
Number toprightscale,
Number bottomrightscale}

Here is a simple Example:

function topleft() {
  let fps = getVal("fps");
  setVal("fpsbutdifferent", fps+2);
  return "thy fps+2 is " + getVal("fpsbutdifferent");
}

more documentation will come out sometime soon.