Skip to content

Lesson 5: Logic Blocks

Logic blocks let objects react to events — clicks, ticks, collisions.

Concept: on_click, on_tick

holoscript
orb "Counter" {
  color: "purple"
  scale: 0.5

  @grabbable

  logic "interactions" {
    let count = 0

    on_click: () => {
      count += 1
      this.color = count % 2 === 0 ? "purple" : "orange"
    }

    on_tick: (dt) => {
      this.rotation.y += 30 * dt   # rotate 30°/s
    }
  }
}

Event handlers

HandlerTrigger
on_clickUser clicks / selects the object
on_tickEvery frame (receives delta time dt)
on_grabUser picks up (requires @grabbable)
on_releaseUser drops the object
on_collidePhysics collision (requires @physics)

Try it:

holoscript
orb "SpinBox" {
  color: "cyan"
  logic "spin" {
    on_tick: (dt) => {
      this.rotation.y += 90 * dt
    }
  }
}

Your turn:

Make the box change color to "red" when clicked and back to "cyan" when clicked again.

[Check Answer] [Hint] [Skip]


Next: Lesson 6 – Directives

Released under the MIT License.