UtilLogic

Provides various utilities.

# Properties

[{"index":"number ElapsedSeconds","0":"Returns the elapsed time in seconds after initializing the current world. The value of elapsed time after the point for the server to create the world and for the client to connect."}]

[{"index":"number ServerElapsedSeconds","0":"The value of elapsed time since the world was created on the server."}]

# Methods

[{"index":"table ConcaveHull(table points, float concavity, float samplingWeight)","0":"After finding a concave polygon that wraps all of the points, it returns the points that make up the polygon. Returned points are sorted by link order. Concavity indicates how concave the polygon is and can take values between 0 and 1. The larger the samplingWeight value, the more points are selected to create the polygon. Values from 0 and higher can be used, and we recommend using a value between 1 and 1.2."}]

[{"index":"boolean Contains(string origin, string targetString)","0":"Checks if the targetString is included in the origin sentences."}]

[{"index":"table ConvexHull(table points)","0":"After finding a convex polygon that wraps all of the points, it returns the points that make up the polygon. Returned points are sorted by link order."}]

[{"index":"DateTime GetLocalTimeFrom(DateTime dateTime) (ClientOnly)","0":"Creates LocalDateTime based on dateTime and returns it."}]

[{"index":"table> GetSpriteEdgePoints(Sprite sprite) (ClientOnly) (Yield)","0":"After finding the border of a sprite, it returns the points that make up the border. Returned points are sorted by link order. The border can be singular or multiple."}]

[{"index":"string GetUTCNow() (Deprecated)","0":"This is a deprecated function. Use the UtcNow property of DateTime."}]

[{"index":"string Insert(string origin, int32 insertIndex, string otherString)","0":"Adds otherString to the insertIndex position of origin sentences."}]

[{"index":"boolean IsNilorEmptyString(string origin)","0":"Determines if the origin string is nil or an empty string."}]

[{"index":"string NewGuid()","0":"Creates a new GUID and returns it. The created GUID will be a 32-digit hexadecimal string with no hyphens."}]

[{"index":"number RandomDouble()","0":"Returns a random real number between 0.0 and 1.0. 1.0 is excluded."}]

[{"index":"int32 RandomInteger()","0":"Returns a random non-negative integer. Uses integers up to and including 2147483647."}]

[{"index":"int32 RandomIntegerRange(int32 min, int32 max)","0":"Returns a random integer within a range. The range includes the min and max values."}]

[{"index":"string Remove(string origin, string targetString)","0":"Finds targetString in the origin statement and deletes the first one it finds."}]

[{"index":"string Replace(string origin, string targetString, string newString)","0":"Replaces the targetString of the origin sentence with the newString."}]

[{"index":"void SetClientTimeScale(float timeScale) (ClientOnly)","0":"Controls the speed in which game time flows in the client.The default value is 1. Values between 0 and 100 can be set. The value is reset to the default value upon moving rooms.timescale changes the deltaTime value that's delivered through OnUpdate(). It doesn't change or affect the actual execution speed of the client. For example, if the timeScale value is 2, time will flow twice as fast, and if the value is 0.5, time will flow half as fast. If the value is 0, the world time will stop."}]

[{"index":"table Split(string origin, string separator = \"\", boolean useSeparatorAsOne = true)","0":"Divides the origin sentence by the separator."}]

[{"index":"table StringToTable(string str)","0":"Converts the string into Table form."}]

[{"index":"void StringToTable(table table, string str)","0":"Converts the string into Table form."}]

[{"index":"string SubString(string origin, int32 startIndex, int32 length = 0)","0":"Returns from the startIndex of the origin sentence."}]

[{"index":"string TableToString(table table)","0":"Converts the Table into string form."}]

[{"index":"string Trim(string origin, string trimString = \"\")","0":"The characters contained in trimString are removed from before\/after."}]

[{"index":"string TrimEnd(string origin, string trimString = \"\")","0":"The characters contained in trimString are removed from a tail."}]

[{"index":"string TrimStart(string origin, string trimString = \"\")","0":"The characters contained in trimString are removed from a head."}]

##### inherited from Logic:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the key-type event and its handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Examples

The following example code shows the return value of each function.
    
    
    @Component
    script UtilityDemo extends Component
        @ExecSpace("ClientOnly")
        method void OnBeginPlay()
        local utc = _UtilLogic:GetUTCNow()
        log("GetUTCNow : " .. tostring(utc))                                   -- MM/dd/yyyy HH:mm:ss.fff
    
        local randomInteger = _UtilLogic:RandomInteger()
        log("RandomInteger : " .. tostring(randomInteger))                     -- 0 ~ 2147483646
    
        local randomIntegerRange = _UtilLogic:RandomIntegerRange(1, 5)
        log("RandomIntegerRange : " .. tostring(randomIntegerRange))           -- 1 ~ 5
    
        local randomDouble = _UtilLogic:RandomDouble()
        log("RandomDouble : " ..  tostring(randomDouble))                      -- 0.0 ~ 1.0
    
        local empty = _UtilLogic:IsNilorEmptyString("")
        log("IsNilorEmptyString : " .. tostring(empty))                        -- true
    
        local trim = _UtilLogic:Trim("[testString]", "[]")
        log("Trim : " .. tostring(trim))                                       -- testString
    
        local trimStart = _UtilLogic:TrimStart("[testString]", "[]")
        log("TrimStart : " .. tostring(trimStart))                             -- testString]
    
        local trimEnd = _UtilLogic:TrimEnd("[testString]", "[]")
        log("TrimEnd : " .. tostring(trimEnd))                                 -- [testString
    
        local replace = _UtilLogic:Replace("@!testString@!", "@!", "*")
        log("Replace : " .. tostring(replace))                                 -- *testString*
    
        local contains = _UtilLogic:Contains("abcdefg", "bcd")
        log("Contains : " .. tostring(contains))                               -- true
    
        local split = _UtilLogic:Split("1,2,3,4,5", ",")
        log("#Split : " .. tostring(#split))                                   -- 5
    
        local subString = _UtilLogic:SubString("abcdefg", 1, 3)
        log("SubString : " .. tostring(subString))                             -- abc
    
        local insert = _UtilLogic:Insert("abcde", 2, "123")
        log("Insert : " .. tostring(insert))                                   -- a123bcde
    
        local table1 = { "first", "second" }
        local tableToString = _UtilLogic:TableToString(table1)
        log("TableToString : " .. tostring(tableToString))                    
        --[[ Int64    1    String    first
             Int64    2    String    second --]]
    
        local table2 = _UtilLogic:StringToTable(tableToString)
        for i = 1, #table2 do
        	log(table2[i])
        end
        -- first
        -- second
        end
    end
    

The built-in script, PlayerAttack, uses the RandomDouble() function to trigger a critical attack based on a specified probability.
    
    
    @Component
    script CriticalHitDeterminer extends Component
        method boolean CalcCritical(Entity attacker, Entity defender, string attackInfo)
        return _UtilLogic:RandomDouble() < 0.3
        end
    end
    

# SeeAlso

  * global