# 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:
# Script mechanism
Script Execution Principle：
The script is triggered by event, and the player can fill the corresponding method in the event
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
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]
Add Game.Start event code:
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：
- The Player.Init event is triggered when Player enters the room
- The Game.Start event is triggered when the Game starts
- The Game triggers a Game.Run event every 0.05 seconds
- After the Game ends, the Game.End event will be triggered, or you can call 'Game:doGameEnd()' to End the Game
- The Game.TimeOver event is triggered when the Game timeout ends
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) end 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: