mvbg

VM_ACTOR_ACTIVATE

VM_ACTOR_ACTIVATE is a GBVM instruction used to make an actor (a character or object in your game world) active and visible, allowing it to participate in game logic, movement, and rendering.

Purpose: In Game Boy games, actors are often managed to optimize performance and control their appearance. VM_ACTOR_ACTIVATE is essential for:

When an actor is activated, it typically becomes visible on screen (if its position is within the camera view) and its associated behaviors (like movement scripts or animation loops) begin to run.

Syntax:

VM_ACTOR_ACTIVATE ACTOR

Usage Example: Spawning an NPC in a Village

Imagine a village scene where certain NPCs only appear after a specific event has occurred (e.g., completing a quest). You can keep these NPCs deactivated initially and then activate them when needed.

; In your script, after a quest is completed:

; Assume VAR_QUEST_COMPLETE_FLAG is set to 1 when the quest is done
VAR_QUEST_COMPLETE_FLAG:
  .R_INT8 0

; Assume NPC_VILLAGER_QUEST_GIVER is the actor ID for the quest giver
NPC_VILLAGER_QUEST_GIVER:
  .R_INT8 10 ; Example Actor ID

; ... code for quest completion ...

; Check if the quest is complete
VM_IF_CONST .EQ, VAR_QUEST_COMPLETE_FLAG, 1, ACTIVATE_QUEST_GIVER, 0
  VM_JUMP END_QUEST_CHECK

ACTIVATE_QUEST_GIVER:
  ; Activate the quest giver NPC
  VM_ACTOR_ACTIVATE NPC_VILLAGER_QUEST_GIVER

  ; Set their initial position (if not already set or if they move)
  VM_ACTOR_SET_POS NPC_VILLAGER_QUEST_GIVER, 5, 8 ; Example coordinates

  VM_LOAD_TEXT TEXT_QUEST_GIVER_APPEARS
  VM_DISPLAY_TEXT
  VM_IDLE 60

END_QUEST_CHECK:
  ; ... continue script ...

TEXT_QUEST_GIVER_APPEARS:
  .TEXT "A mysterious villager has appeared!"
  .TEXT_END

In this example, VM_ACTOR_ACTIVATE NPC_VILLAGER_QUEST_GIVER makes the specified NPC actor visible and enables its associated behaviors. This allows for dynamic changes in the game world, where characters or objects can appear and disappear based on game progression.

Analogy to other programming languages: This is analogous to enabling or setting an object’s active or visible property to true in a game engine like Unity (gameObject.SetActive(true)) or Godot (node.show()). It’s about controlling the lifecycle and presence of game entities within the active scene.