# How does the script work?

  • Developer script is based on What is lua script, with perfect combination of Mini World, and provide lots ofMini World APIs and functions of the scripting language. Byu sing scripts, you can develop a lot of fun gameplay.


The following options are optional for learning about script:

Understand the mechanics of scripting

Basic Script Examples and Interpretations

What is lua script

Mini World APIs

# Script mechanism

Script Execution Principle:

The script is triggered by event, and the player can fill the corresponding method in the event

  1. The developer script provides default global objects, the global object corresponding to event is ScriptSupportEvent, other global objects can be referred to mini world APIs

  2. Players need to manually add events, such as Game.Start event will be executed at the beginning of the Game. More detail about event types and return parameters can be found in [event system]

  3. Add Game.Start event code:

ScriptSupportEvent:registerEvent([=[Game.Start]=], Game_StartGame) 

Note: the event of the Game, except game.start, other events are not required to write, use what you need

How to use event:

How do you know which events should be used in the game, given that the script is based on events??

Here are some examples:

  1. The Player.Init event is triggered when Player enters the room
ScriptSupportEvent:registerEvent([=[Player.Init]=], Player_Init) 
  1. The Game.Start event is triggered when the Game starts
ScriptSupportEvent:registerEvent([=[Game.Start]=], Game_StartGame) 
  1. The Game triggers a Game.Run event every 0.05 seconds
ScriptSupportEvent:registerEvent([=[Game.Run]=], Game_Run) 
  1. After the Game ends, the Game.End event will be triggered, or you can call 'Game:doGameEnd()' to End the Game
ScriptSupportEvent:registerEvent([=[Game.End]=], Game_End) 
  1. The Game.TimeOver event is triggered when the Game timeout ends
ScriptSupportEvent:registerEvent([=[Game.TimeOver]=], Game_TimeOver) 

When something happens in the game, it can trigger an event, or you can check more Event-System

Associate between multiple scripts

A game scenario may contain multiple script files, so how do they relate to each other? Here's an example:

-- At the beginning of the game, we wish a chat box prompt 'Hello!Mini world'.

-- The first script is named: test1 and contains:
_G.sayHello = 'Hello!Mini world'

-- The first script is named: test2 and contains:
Game_StartGame = function()
	Chat:sendChat(_G.sayHello, 1)
ScriptSupportEvent:registerEvent([=[Game.Start]=], Game_StartGame)

--Based on the explanation above, can you tell which event is used in this code?

# Note: if we want to use the method created in the second script from the first script, we need to use _G to create and associate the call

Still don't understand?

That's ok, let's look at some examples:

Last Update: 4/15/2020, 6:29:50 PM