Skip to content

Global Functions & Statements

Omar Mohamed edited this page Mar 24, 2026 · 7 revisions

Global Functions & Statements

These are available globally in every script without needing a type instance.


Functions

importScript(packId, script)

Imports a reusable Vyn script library from a resource pack. Use this to share common logic across multiple scripts.

  • Parameters:
    • packIdString — The resource pack ID that contains the script
    • scriptString — The name of the script to import
importScript("mypack", "math_utils")
importScript("mypack", "animation_lib")

excludeScript(packId, script)

Disables an active script, preventing it from running.

  • Parameters:
    • packIdString — The resource pack ID that owns the script
    • scriptString — The name of the script to disable
~ Disable a script conditionally
check modLoader.isModLoaded("somemod") do
    excludeScript("mypack", "compat_script")
end

debugText(text)

Displays a debug string on screen. Only works when Resource Pack Debug Mode is enabled in the mod config (see InteractiveStuffConfig).

Recommended to use it inside the onTick event!

  • Parameters:
    • textString — The text to display
task onTick do
   debugText("Player health: " + player.getHealth())
   debugText("Biome: " + player.getWorld().getBiomeAt(player.getPosition()))
   debugText("Velocity Y: " + player.getVelocityY())
end

getDelta()

Returns the normalized frame delta time. Use this to make animations and transitions framerate-independent — the result scales consistently at any FPS.

  • Returns: Double
~ Rotate item at a consistent speed regardless of FPS
make item player.getMainHandItem()
item.rotateY(90 * getDelta())

~ Smooth translation using delta
make speed = 0.05
item.translateY(speed * getDelta())

Statements

wait <ticks> do ... end

Executes a block of code after a delay of the given number of ticks (20 ticks = 1 second). The rest of the script continues running immediately — the wait block runs in the background.

  • Parameters:
    • ticksInteger — Number of ticks to wait before executing the body
~ Play a sound, then play another sound 1 second later
player.playSound("minecraft:entity.experience_orb.pickup", 1.0, 1.0)

wait 20 do
    player.playSound("minecraft:block.note_block.bell", 1.0, 1.2)
end
~ Delayed debug message
debugText("Starting sequence...")

wait 40 do
    debugText("2 seconds have passed!")
end
~ Chained waits
wait 10 do
    debugText("0.5 seconds")
    wait 10 do
        debugText("1 second")
        wait 20 do
            debugText("2 seconds")
        end
    end
end

Events

Events are special tasks that Vyn calls automatically when something happens in the game. Define them in your script using task and Vyn will invoke them at the right time.


onTick

Called every game tick (20 times per second). Use this for logic that needs to run on a fixed tick schedule rather than every render frame.

task onTick do
    debugText("XP Level: " + player.getExperienceLevel())
end

onSwingHand

Called when the player swings their hand (left-click attack or animation trigger).

task onSwingHand do
    player.playSound("minecraft:entity.player.attack.weak", 0.5, 1.2)
end
task onSwingHand do
    debugText("Swung! Holding: " + player.getMainHandItem().getName())
end

onPlaySound takes sound

Called when the game plays a sound. Receives the Sound that is about to play, allowing you to react to or inspect it.

  • Parameters:
    • soundSound — The sound being played
task onPlaySound takes sound do
    debugText("Sound: " + sound.getName())
end
~ React to a specific sound playing
task onPlaySound takes sound do
    check sound.getName() == "minecraft:block.note_block.harp" do
        player.playSound("minecraft:block.note_block.bell", sound.getVolume(), sound.getPitch())
    end
end

onKeyPress takes keyInput

Called when the player presses a key. Receives the key code as an integer, allowing you to react to specific key inputs.

  • Parameters:
    • keyInputInteger — The key code of the pressed key
~ Log any key press
task onKeyPress takes keyInput do
    debugText("Key pressed: " + keyInput)
end
~ React to a specific key (e.g. key code 69 = E, the default "pick block" / use key)
task onKeyPress takes keyInput do
    check keyInput == 69 do
        player.playSound("minecraft:ui.button.click", 1.0, 1.0)
    end
end

onItemUpdate takes itemRendered

Called every render frame for each item being rendered. This is the primary event for applying visual transforms, physics, color changes, and model overrides to held items.

  • Parameters:
    • itemRenderedItemModel — The item currently being rendered

Always guard with player.getGamemode() != "spectator" to avoid running logic while spectating.

task onItemUpdate takes itemRendered do
    check player.getGamemode() != "spectator" do
        check itemRendered.getName() == "minecraft:diamond_sword" do
            itemRendered.setColor(100, 180, 255)
        end
    end
end
~ Physics-based sway on a specific item
importScript("interactivestuff:interactive_resourcepack", "physics_lib")

task onItemUpdate takes itemRendered do
    check !modLoader.isModLoaded("holdmyitems") do
        check player.getGamemode() != "spectator" do
            check itemRendered.getName() == "minecraft:stick" do
                runPhysicsEngine(0.01, 0.15, -1.0, 0.3, 0.5, 1.0, 45, 0.1)
                itemRendered.setPivot(0.0, -0.01, 0.0)
                itemRendered.rotate(angleX, 0, angleZ)
            end
        end
    end
end

📖 InteractiveStuff Docs


🧱 Types


⚙️ Scripting

📃 Built-in Library

Clone this wiki locally