Utilizing Annotations

# Course Introduction

Annotation is a kind of metadata that you can use by adding to a code. While the Comment using the `--` symbol in the script serves only as a reference for writing the script. Writing an Annotation in the format of `---@` can enable the help of script assists such as Quick Info, Signature Helper, Code Completion, etc. Let's take a look at the types of Annotation offered in MapleStory Worlds and how to utilize them through this course.

> Learn more Check out the Script Assist item in the [Script Editor Orientation](/ko/docs/?postId=56) guide if you want details on Quick Info, Signature Helper, and Code Completion.

# Specifying Variable Type: Type Annotation

Script Assist can provide support in the Script Editor when the variable type is explicitly specified as Type Annotation. Type Annotation is applied to an assigned line.

## Usage

Type Annotation is used as follows.

[png](166788442640966b092935ab7482d948c6fc39188d48c)
    
    
    @Component
    script ServerInitializer extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            ---@type string
            local testValue = "test"
        end
    end
    

## Example

##### Lua Functions that Cannot Deduct Return Type

Likewise, use Type Annotation when you retrieve a resulting Lua function value that cannot deduct return type as follows.
    
    
    @Component
    script TestFunctionRunner extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local function TestFunction()
                return "strValue"
            end
            
            local strValue = TestFunction()
        end
    end
    

  


[{"index":"Before the application of Type Annotation","0":"[png](166788677395339c9be52267845a1a38273071868699e)"},{"index":"After the application of Type Annotation","0":"[png](1667886963732dbed1d6d12984f79bd1922548876854f)"}]

  
##### When Multiple Values are Assigned Likewise, use **Type Annotation** when multiple values are assigned as follows. ```lua @Component script MultiReturnExample extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() local function TestFunction() return "strValue", 5 end 
    
    
        
        local strValue, intValue = TestFunction()
    end
    

end
    
    
      
    
    | Before the application of Type Annotation | After the application of Type Annotation |
    | :---: | :---: |
    | [png](1667887186926acb2c0f5eac64f118c480078c23b2ac4) | [png](1667892117117387cdcbbe65e4aa08d76b2fc548d48ad) |
      
    
    You can specify partially when multiple values are assigned. Specifying a rear value alone is impossible because the specified type is applied from a front value.
    
    | Before the application of Type Annotation | After the partial application of Type Annotation |
    | :---: | :---: |
    | [png](1667887186926acb2c0f5eac64f118c480078c23b2ac4) | [png](166789228646766e78448a0794b3cb971c4492954f34f) |
    
    
    ## Specifying Generic Type
    To specify a generic type, follow this example.
    

@Component script ServerBootstrapper extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type any end end
    
    
    ##### Usage Example
    

@Component script ServerInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type string local testValue = "test" end end
    
    
      
    
    

@Component script StartupValueInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type string, integer local strValue, intValue = "str", 5 end end
    
    
      
    
    Various types such as event, component, entity, and Enum besides simple primitive types can be specified as **Type Annotation**.
    
    ## Specifying Table Type
    To specify the type of a Table, follow this example.
    

@Component script ServerInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type table end end
    
    
    ##### Example
    

@Component script ServerDataInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type table local testTable = {} end end
    
    
      
    
    

@Component script ServerEntitySetup extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type table local testTable = {} end end
    
    
      
    
    

@Component script ServerEntityMap extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type table local testTable = {} end end
    
    
      
    
    For example, you can check related information in Quick Info when specifying **Type Annotation** as follows.
    

@Component script DataTableTest extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() local function TestFunction() local testTable = {} testTable[1] = "A" testTable[2] = "B" testTable[3] = "C" end
    
    
        
        ---@type table
        local tableValue = TestFunction()
    end
    

end
    
    
    [png](1667895925609146ce9442a4f4e6da96fc1aa6932f744)
    
    ## Specifying Function Type
    To specify the type of a Function, follow this example.
    

@Component script ServerInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type function(param_name: any):any end end
    
    
    ##### Example
    

@Component script ServerStartBehavior extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type function() local testFunction = function() end end end
    
    
      
    
    

@Component script FunctionInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type function(testParamA:string, testParamB:Entity) local testFunction = function(testParamA, testParamB) end end end
    
    
      
    
    

@Component script AttackComponentResolver extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type function(testParamA:string, testParamB:Entity):AttackComponent local testFunction = function(testParamA, testParamB) return atkComponent end end end
    
    
      
    
    

@Component script AttackFunctionSetup extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type function(testParamA:string, testParamB:Entity):AttackComponent, string local testFunction = function(testParamA, testParamB) return atkComponent, "strValue" end end end
    
    
      
    
    

@Component script AttackComponentProvider extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type (function(testParamA:string, testParamB:Entity):AttackComponent, string), Entity local testFunction, testEntity = function(testParamA, testParamB) return atkComponent, "strValue" end, self.Entity end end end
    
    
      
    
    For example, you can get help from Signature Helper when specifying **Type Annotation** as follows.
    

@Component script FunctionProvider extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() local function TestFunction() return function(paramA, paramB) return "strValue", false end end
    
    
        
        ---@type function(paramA:string, paramB:AttackComponent):string, boolean
        local test = TestFunction()
    end
    

end
    
    
    [png](1669633527104fde7bdfed20d4bdb802bdec69d11e4fb)
      
    
    You can also check the specified type in Quick Info.
    

@Component script AttackComponentInvoker extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type function(paramA:string, paramB:AttackComponent):string, boolean local test = TestFunction() local strValue, boolValue = test("param", self.Entity.AttackComponent) end end
    
    
    [png](1667893299258103b46b267b745f882a40a4cbb70c568)
      
    
    Divide each type into groups with parenthesis when you want to specify other values along with a function that returns multiple values.
    

@Component script AttackFunctionProvider extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@type (function(paramA:string, paramB:Entity):AttackComponent,string), Entity local testFunction, testEntity = function(testParamA, testParamB) return atkComponent, "strValue" end, self.Entity end end end
    
    
    
    # Specifying Parameter Type: Param Annotation
    
    Script Assist can provide support when the parameter type of a target function is specified using **Param Annotation**. **Param Annotation** is applied to a function-defining line.
    
    Use the following syntax for **Param Annotation**:
    

@Component script ServerInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@param param_name any end end
    
    
    ##### Usage Example
    

@Component script EntityTester extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@param testParamA Entity local function TestFunction(testParamA) end end end
    
    
      
    
    

@Component script TestFunctionInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@param testParamA Entity \---@param testParamB integer local function TestFunction(testParamA, testParamB)
    
    
        
        end
    end
    

end
    
    
      
    
    Basically, type deduction is impracticable because one cannot know what type will be inserted into a parameter when defining Lua function. Let's use **Param Annotation** in this case.
    
    | Before the application of Param Annotation | After the application of Param Annotation |
    | :---: | :---: |
    | [png](166789361996144188e4993ee4a6a8a4d0bddeb7229ae) | [png](1667893634012f417287ece184076a6dae5259609f80e)   
    [png](1668671082158866bdb58d8bf4710b2df2fab3d00ce47) |
    
    # Specifying Return Type: Return Annotation
    
    Script Assist can provide support when the return type of a target function is specified using **Return Annotation**. **Return Annotation** is applied to a function-defining line.
    
    Use the following syntax for **Return Annotation**.
    

@Component script ServerInitializer extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@return any end end
    
    
    ##### Example
    

@Component script TestFunction extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@return Entity local function TestFnction(testParamA, testParamB) return self.Entity end end end
    
    
      
    
    

@Component script EntityStringProvider extends Component @ExecSpace("ServerOnly") method void OnBeginPlay() \---@return Entity, string local function TestFunction(testParamA, testParamB) return self.Entity, "strValue" end end end
    
    
      
    
    | Before the application of Return Annotation | After the application of Return Annotation |
    | :---: | :---: |
    | [png](1667893987810443dd08fe02842e19a29e8d2b7d14b54) | [png](1667894003787ca547259d8d0414294064f26fd6569ac) |