Write Your First JavaScript Script for Graal Mod
Setting Up Your Script File
Graal Mod allows you to write ECMAScript-compliant JavaScript code that runs directly in your Minecraft environment. Start by creating a .js file in your scripts folder (location depends on your mod loader setup).
Basic Script Structure
Begin with a simple test script:
`javascript
console.log("Hello from Graal!");
`
This confirms your script loads correctly. From here, you can expand to interact with game events and Java objects. Graal Mod automatically compiles and executes your code when the game loads or when you trigger a reload.
Accessing Java Objects
One of Graal's strengths is seamless Java interoperability. You can call Java methods and access fields directly from JavaScript:
`javascript
var player = /* reference to player object */;
player.sendMessage("Script executed!");
`
Consult the mod's documentation for available Java bindings in your specific setup. Test incrementally—add one feature, verify it works, then expand. Use console.log() for debugging output visible in your game logs.