【问题标题】:Roblox Problem: Expected ')' (to close '(' at column 18), got '='Roblox 问题:预期为 ')'(在第 18 列关闭 '('),得到 '='
【发布时间】:2020-08-11 11:08:10
【问题描述】:

您好,我正在尝试制作飞行脚本,我只需要有关“)”的帮助,老实说,我找不到放置它的位置。我知道这是一个菜鸟的错误,我很抱歉浪费了时间。我不得不过度解释这一点,很抱歉,我无法发布任何其他方式。

local camera = game.Workspace.CurrentCamera;

local character = game.Players.LocalPlayer.ChracaterAdded:Wait();
    local F = game.Players.LocalPlayer.Backpack.Bold
local hrp = character:WaitForChild("HumanoidRootPart");
local humanoid = character:WaitForChild("Humanoid");
local animate = character:WaitForChild("Animate");

while (not character.Parent) do character.AncestryChanged:Wait(); end
local idleAnim = humanoid:LoadAnimation(script:WaitForChild("IdleAnim"));
local moveAnim = humanoid:LoadAnimation(script:WaitForChild("MoveAnim"));
local lastAnim = idleAnim;

local bodyGyro = Instance.new("BodyGyro");
bodyGyro.maxTorque = Vector3.new(1, 1, 1)*10^6;
bodyGyro.P = 10^6;

local bodyVel = Instance.new("BodyVelocity");
bodyVel.maxForce = Vector3.new(1, 1, 1)*10^6;
bodyVel.P = 10^4;

local isFlying = false;
local isJumping = false;
local movement = (forward = 0, backward = 0, right = 0, left = 0);
local FAD = F.Flying;

--------------Functions--------------

local function setFlying(flying)
    isFlying = flying;
    bodyGyro.Parent = isFlying and hrp or nil;
    bodyVel.Parent = isFlying and hrp or nil;
    bodyGyro.CFrame = hrp.CFrame;
    bodyVel.Velocity = Vector3.new();

    animate.Disabled = isFlying

    if (isFlying) then
        FAD.Transparency = 1
        lastAnim = idleAnim;
        lastAnim:Play();
    else
        FAD.Transparency = 0
        lastAnim:Stop();
    end
end

local function onUpdate(dt)
    if (isFLying) then
        local cf = camera.CFrame;
        local direction = cf.rightVector*(movement.right - movement.left) + cf.lookVector*(movement.foward - movement.backward);

    if (direction:Dot(direction) > 0) then
        direction = direction.unit;
    end

    bodyGyro.CFrame = cf;
    bodyVel.Velocity = direction * humanoid.WalkSpeed * 3
    end
end

local function onJumpRequest()
    if (not humanoid or humanoid:GetState() == Enum.HumanoidStateType.Dead) then
        return;
    end

    if (isFlying) then
        setFlying(false);
        isJumping = false;
    else if (isJumping) then
        wait(0.5)setFlying(true);
    end
end

local function onStateChange(old, new)
    if (new == Enum.HumanoidStateType.Landed) then

        isJumping = false;
    elseif (new == Enum.HumanoidStateType.Jumping) then
        isJumping = true;
    end
end

local function movementBind(actionName, inputState, inputObject)
    if (inputState == Enum.UserInputState.Begin) then
        movement[actionName] = 1;
    elseif (inputState == Enum.UserInputState.End) then
        movement[actionName] = 0;
    end

    if (isFlying) then
        local isMoving = movement.right + movement.left + movement.foward + movement.backward > 0;
        local nextAnim = isMoving and moveAnim or idleAnim;
        if (nextAnim ~= lastAnim) then
            lastAnim:Stop();
            lastAnim = nextAnim;
            lastAnim:Play();
        end
    end
    return Enum.ContextActionResult.Pass;

end
-------------Connections-------------

humanoid.StateChanged:Connect(onStageChange);
game:GetService("UserInputService").JumpRequest:Connect(onJumpRequest);


game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterFoward);
game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackard);
game:GetService("ContextActionService"):BindAction("left", movementBind, false, Enum.PlayerActions.CharacterLeft);
game:GetService("ContextActionService"):BindAction("right", movementBind, false, Enum.PlayerActions.CharacterRight);

    game:GetService("RunService").RenderStepped:Connect(onUpdate)

【问题讨论】:

  • local movement 声明中,括号内的内容是无效的语法(除非 Roblox 以某种方式更改了语法)。那条线应该做什么?

标签: lua roblox


【解决方案1】:

在第 18 行,movement 的值应该是dictionary,而不是括号内的变量。

local movement = {forward = 0, backward = 0, right = 0, left = 0}

【讨论】:

    猜你喜欢
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    • 2019-07-22
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多