【问题标题】:Attempt to index a nil value (field 'SpawnPoint)'尝试索引一个零值(字段'SpawnPoint)'
【发布时间】:2019-04-29 00:02:05
【问题描述】:

我为我的一个朋友创建了一个 5m 服务器,但我目前遇到了车库问题。目前正在尝试索引 'spawnpoint' 的 nil 值

            for i=1, #v.Vehicles, 1 do

                if GetDistanceBetweenCoords(coords,  v.Vehicles[i].Spawner.x,  v.Vehicles[i].Spawner.y,  v.Vehicles[i].Spawner.z,  true) < Config.MarkerSize.x then
                    isInMarker     = true
                    currentStation = k
                    currentPart    = 'VehicleSpawner'
                    currentPartNum = i
                end

                if GetDistanceBetweenCoords(coords,  v.Vehicles[i].SpawnPoint.x,  v.Vehicles[i].SpawnPoint.y,  v.Vehicles[i].SpawnPoint.z,  true) < Config.MarkerSize.x then
                    isInMarker     = true
                    currentStation = k
                    currentPart    = 'VehicleSpawnPoint'
                    currentPartNum = i
                end

            end

【问题讨论】:

  • 好吧,不是每个v.Vehicles 都有SpawnPoint

标签: indexing lua null


【解决方案1】:

正如 brianolive 已经说过的,似乎不是每个v.Vehicle 都有一个SpawnPoint。例如,您可以通过验证 SpawnPoint 的存在来解决此问题。

if v.Vehicles[i].SpawnPoint and (
  GetDistanceBetweenCoords(
    coords, v.Vehicles[i].SpawnPoint.x, v.Vehicles[i].SpawnPoint.y,
    v.Vehicles[i].SpawnPoint.z, true
  ) < Config.MarkerSize.x
) then

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-15
    • 2016-09-19
    • 2012-03-12
    • 2020-05-28
    • 1970-01-01
    • 2019-10-10
    相关资源
    最近更新 更多