如何在 LUA 中使用非整数而不使用浮点数

在 LUA 中,我无法使用浮点数来 MoveMouse。所以我需要找到一种解决方法。我不知道如何做到这一点,所以我需要帮助。

function OnEvent(event, arg)
    local multiplier = 2
         if smth == CODE then
                MoveMouseRelative(-1*multiplier, 0.1*multiplier)
                Sleep(10)
                MoveMouseRelative(-1*multiplier, 0.2*multiplier)
                Sleep(10)
点赞
用户1847592
用户1847592

你可以在变量中存储小数 value,并将 math.floor(value) 传递给你的函数。

未使用的小数部分将被积累以供将来使用。

local x_frac, y_frac = 0

local function MoveMouseRelativeFractional(x, y)
   x_frac = x_frac + x
   y_frac = y_frac + y
   local x_int = math.floor(x_frac)
   local y_int = math.floor(y_frac)
   x_frac = x_frac - x_int
   y_frac = y_frac - y_int
   if x_int ~= 0 or y_int ~= 0 then
      MoveMouseRelative(x_int, y_int)
   end
end

function OnEvent(event, arg)
   local multiplier = 2
   if smth == CODE then
      MoveMouseRelativeFractional(-1*multiplier, 0.1*multiplier)
      Sleep(10)
      MoveMouseRelativeFractional(-1*multiplier, 0.2*multiplier)
      Sleep(10)
2021-05-16 21:46:21