RunService

Mostrar obsoleto

*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.

No creable
Servicio
No replicado

RunService contiene métodos y eventos para la gestión del tiempo, así como para la gestión del contexto en el que se ejecuta una experiencia o un script.Métodos como IsClient() , IsServer() y IsStudio() pueden ayudarte a determinar bajo qué código de contexto se está ejecutando.Estos métodos son útiles para ModuleScripts que pueden ser requeridos por tanto por los scripts del cliente como del servidor.Además, IsStudio() se puede utilizar para agregar comportamientos especiales para las pruebas en el estudio.

RunService también alberga eventos que permiten que tu código se adhiera al bucle de marco por marco de Roblox, como PreRender , PreAnimation , PreSimulation , PostSimulation y Heartbeat .Seleccionar el evento adecuado para usar en cualquier caso es importante, por lo que debe leer Programador de tareas para tomar una decisión informada.

Resultados de prueba de contexto

<th><code>Class.RunService:IsStudio()|IsStudio</code></th>
<th><code>Class.RunService:IsClient()|IsClient</code></th>
<th><code>Class.RunService:IsServer()|IsServer</code></th>
<th><code>Class.RunService:IsEdit()|IsEdit</code></th>
<th><code>Class.RunService:Está corriendo()|Está corriendo</code></th>
<th><code>Class.RunService:IsRunMode()|IsRunMode</code></th>
</tr>
</thead>
<tbody>
<tr>
<td>Jugador en vivo</td><td><code>falso</code></td><td><code>verdadero</code></td><td><code>falso</code></td>
<td />
<td />
<td />
</tr>
<tr>
<td>Servidor en vivo</td><td><code>falso</code></td><td><code>falso</code></td><td><code>verdadero</code></td>
<td />
<td />
<td />
</tr>
<tr>
<td>Modo de edición</td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>falso</code></td>
</tr>
<tr>
<td>Edición colaborativa</td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>falso</code></td>
</tr>
<tr>
<td>Modo ejecutar</td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
</tr>
<tr>
<td>Modo de juego (cliente)</td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
</tr>
<tr>
<td>Modo de juego (servidor)</td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
</tr>
<tr>
<td>Prueba de equipo (jugador)</td>
<td><code>cierto</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
</tr>
<tr>
<td>Prueba en equipo (servidor)</td>
<td><code>falso</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
<td><code>cierto</code></td>
<td><code>falso</code></td>
</tr>
</tbody>
Entorno

Resumen

Propiedades

Métodos

  • BindToRenderStep(name : string,priority : number,function : function):()

    Dada una nombre de cadena de una función y una prioridad, este método vincula la función a RunService.PreRender.

  • Escribir paralelo

    Devuelve si el entorno actual se está ejecutando en el cliente.

  • Seguridad del plugin
    Escribir paralelo

    Devuelve si el entorno actual está en modo Edit .

  • Escribir paralelo

    Devuelve si el botón Ejecutar se ha presionado para ejecutar la simulación en Studio.

  • Devuelve si la experiencia está actualmente en ejecución.

  • Escribir paralelo

    Devuelve si el entorno actual se está ejecutando en el servidor.

  • Escribir paralelo

    Devuelve si el entorno actual se está ejecutando en Studio.

  • Pause():()
    Seguridad del plugin

    Pausa la simulación de la experiencia si está en ejecución, suspendiendo la física y los scripts.

  • Run():()
    Seguridad del plugin

    Ejecuta la simulación del juego, ejecutando física y scripts.

  • Stop():()
    Seguridad del plugin

    Detiene la simulación de la experiencia si se está ejecutando.

  • Desvincula una función que estaba vinculada al bucle de renderizado usando RunService:BindToRenderStep() .

Eventos

Propiedades

ClientGitHash

Solo lectura
No replicado
Seguridad de scripts Roblox
Leer paralelo
No replicado
Seguridad del plugin
Leer paralelo

Métodos

BindToRenderStep

()

Parámetros

name: string
Valor predeterminado: ""
priority: number
Valor predeterminado: ""
function: function
Valor predeterminado: ""

Devuelve

()

Muestras de código

Frame Moving in Circle

local RunService = game:GetService("RunService")
-- How fast the frame ought to move
local SPEED = 2
local frame = script.Parent
frame.AnchorPoint = Vector2.new(0.5, 0.5)
-- A simple parametric equation of a circle
-- centered at (0.5, 0.5) with radius (0.5)
local function circle(t)
return 0.5 + math.cos(t) * 0.5, 0.5 + math.sin(t) * 0.5
end
-- Keep track of the current time
local currentTime = 0
local function onRenderStep(deltaTime)
-- Update the current time
currentTime = currentTime + deltaTime * SPEED
-- ...and the frame's position
local x, y = circle(currentTime)
frame.Position = UDim2.new(x, 0, y, 0)
end
-- This is just a visual effect, so use the "Last" priority
RunService:BindToRenderStep("FrameCircle", Enum.RenderPriority.Last.Value, onRenderStep)
--RunService.RenderStepped:Connect(onRenderStep) -- Also works, but not recommended
RunService Custom Function

local RunService = game:GetService("RunService")
local function checkDelta(deltaTime)
print("Time since last render step:", deltaTime)
end
RunService:BindToRenderStep("Check delta", Enum.RenderPriority.First.Value, checkDelta)
Bind and Unbind a Function

local RunService = game:GetService("RunService")
-- Step 1: Declare the function and a name
local NAME = "Print Hello"
local function printHello()
print("Hello")
end
-- Step 2: Bind the function
RunService:BindToRenderStep(NAME, Enum.RenderPriority.First.Value, printHello)
-- Step 3: Unbind the function
RunService:UnbindFromRenderStep(NAME)

IsClient

Escribir paralelo

Devuelve

IsEdit

Seguridad del plugin
Escribir paralelo

Devuelve

IsRunMode

Escribir paralelo

Devuelve

IsRunning


Devuelve

IsServer

Escribir paralelo

Devuelve

IsStudio

Escribir paralelo

Devuelve

Pause

()
Seguridad del plugin

Devuelve

()

Run

()
Seguridad del plugin

Devuelve

()

Stop

()
Seguridad del plugin

Devuelve

()

UnbindFromRenderStep

()

Parámetros

name: string
Valor predeterminado: ""

Devuelve

()

Eventos

Heartbeat

Parámetros

deltaTime: number

PostSimulation

Parámetros

deltaTimeSim: number

PreAnimation

Parámetros

deltaTimeSim: number

PreRender

Parámetros

deltaTimeRender: number

PreSimulation

Parámetros

deltaTimeSim: number

RenderStepped

Parámetros

deltaTime: number

Stepped

Parámetros

time: number
deltaTime: number