• Studio

  • Studio API

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • Globals

    In Lua scripting, Globals are essential values or variables that can be accessed from any part of the script without the need to pass them explicitly. They are context-specific and readily available. On the other hand, a Service in Lua script is like a toolbox of static functions that offer convenient utilities for developers to use in their scripts.

    Properties

    ServerAndClient

    The 'self' property is used to access the current script's instance. This is always the owning script of the object as a Class.LuaBehaviour. This is the primary way to get many of the core Unity MonoBehaviour methods and properties like self.gameObject, self:Update and self:OnTriggerEnter. It is highly recommended to familiarize yourself with the Class.LuaBehaviour documentation to understand how to use the 'self' property.

      local objectName = self.gameObject.name
      print("My name is: " .. objectName)
    

    The 'client' property is used to access the current client instance. This is useful for when you want to access the client's information like the client.localPlayer property or client.PlayerConnected event. Read the Class.GameClient documentation to learn more.

      local localPlayer = client.localPlayer
      print("My name is: " .. localPlayer.name)
    
    ServerOnly

    The 'server' property is used to access the current server instance. This is useful for when you want to access the server' information like the server.PlayerConnected event. Read the Class.GameServer documentation to learn more.

    server.PlayerConnected:Connect(function(player)
      print("Player connected: " .. player.name)
    end)
    
    ServerAndClient

    The 'scene' property is used to access the currently active scene.

    scene.PlayerJoined:Connect(function(scene, player)
      print("Player joined: " .. player.name)
    end)
    

    Methods

    ServerAndClient

    Defers the execution of a function to the next frame. This is useful for when you want to run a function after the current frame has finished.

      defer(function()
        print("This will run in the next frame")
      end)
    

    Parameters

    callback

    function

    The function to run in the next frame.

    Returns

    void

    ServerAndClient

    Gets a 'Module' typed script by name as a singleton behaviour, giving access to the hierarchy it is within.

    Using the require method to retrieve a module will automatically load the singleton instance of the behaviour. This is equivalent to using Find and GetComponent to retrieve the behaviour.

      local myModuleScript = require("MyModuleScript")
    

    Parameters

    path

    string

    The script name of the module to load.

    Returns

    LuaBehaviour

    The module that was loaded.

    ServerAndClient

    Gets the string representation of the type of the object. This is useful for debugging and logging as well as learning about what types are being returned by complex methods.

      local v = Vector3.new(1, 2, 3)
      print(typeof(v)) -- prints "Vector3" instead of "userdata" or "(1, 2, 3)"
    

    Returns

    string

    The Type of the object. In question.

    ServerAndClient

    Gets the string representation of the object if one has defined one. This is useful for debugging and logging.

      local v = Vector3.new(1, 2, 3)
      print(tostring(v)) -- prints "(1, 2, 3)" instead of "userdata" or "Vector3"
    

    Returns

    string

    Updated 2 months ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.