Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在lua中获得最大数值?_Lua_Coronasdk - Fatal编程技术网

如何在lua中获得最大数值?

如何在lua中获得最大数值?,lua,coronasdk,Lua,Coronasdk,我正在开发这个应用程序来观察你们的跑步速度,为此我需要一个功能来显示你们的最高速度。但找不到我该怎么办 local speedText = string.format( '%.3f', event.speed ) speed.y = 250 speed.x = 125 local numValue = tonumber(speedText)*3.6 if numValue ~= nil then speed.text = math.round( numValue ) end 我已将我的

我正在开发这个应用程序来观察你们的跑步速度,为此我需要一个功能来显示你们的最高速度。但找不到我该怎么办

local speedText = string.format( '%.3f', event.speed )
speed.y = 250
speed.x = 125
local numValue = tonumber(speedText)*3.6
if numValue ~= nil then
    speed.text = math.round( numValue )
end
我已将我的
speedText
设置为您在上面看到的数字


我在Conora SDK/Lua中编程

当您询问有关堆栈溢出的问题时,应该提供更多信息,但无论如何,让我们尝试帮助您

您的代码可能位于如下所示的事件侦听器中:

local listener = function(event)
  local speedText = string.format( '%.3f', event.speed )
  speed.y = 250
  speed.x = 125
  local numValue = tonumber(speedText)*3.6
  if numValue ~= nil then
      speed.text = math.round( numValue )
  end
end
这将显示当前速度。如果要显示最大速度,只需执行以下操作:

local maxSpeed = 0
local listener = function(event)
  local speedText = string.format( '%.3f', event.speed )
  speed.y = 250
  speed.x = 125
  local numValue = tonumber(speedText)*3.6 or 0
  if numValue > maxSpeed then
      maxSpeed = numValue
      speed.text = math.round( numValue )
  end
end

其思想是:您需要在侦听器(或全局)之外定义一个变量来存储以前的最大速度。每次调用事件侦听器时,如果当前速度高于以前的最大速度,则它是新的最大速度,因此您可以保存并显示它。

我无法撤消您的代码。是否要比较多个“速度”对象?你能给我们一个函数头吗?