1

我想将 Lua 中的已知信息从一个表传递到下一个语言环境,但不知何故,我仍然收到“尝试索引 nil 值”。这可能很愚蠢且易于修复,但我不是程序员,我边走边学。

for k,v in pairs(FoundObjects)do

            if v.HashIs == vehhash then
                print ("Found Model Name: " .. v.ModNam)  -- v.ModNam is known and correct - I want to pass this information down below as "modelName" value
            local   modelName = v.ModNam

            local ped = GetPlayerPed(-1)
            local vehicle = GetVehiclePedIsIn(ped, false)
            local vehhash   = GetEntityModel(vehicle)
            local GetHandling = GetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDragCoeff")
            local currentEngineMod = GetVehicleMod(vehicle, 11)

            originalfInitialDragCoeff = Config.modelName.fInitialDragCoeff   -- when written name of the car instead of "modelName", passing of the value from config file works!
            originalfDriveBiasFront =   Config.modelName.fDriveBiasFront
            originalfSteeringLock = Config.modelName.fSteeringLock
            originalfTractionCurveMax = Config.modelName.fTractionCurveMax
            originalfTractionCurveMin = Config.modelName.fTractionCurveMin
            originalfTractionCurveLateral = Config.modelName.fTractionCurveLateral
            originalfLowSpeedTractionLossMult = Config.modelName.fLowSpeedTractionLossMult

print(modelName)    -- actually prints the value needed!
print(originalfInitialDragCoeff) -- unfortunately, this shows as a Nil
  • vehhash - 是我的游戏角色所在的车辆给出的数值
  • v.ModNam - 正确地将 vehhash 从数字转换为所需汽车的名称
  • modelName - 不幸的是,modelName 不共享实际的汽车名称并向我抛出“尝试索引 nil 值”

originalfInitialDragCoeff = Config.modelName.fInitialDragCoeff

  • 当我要写实际的汽车名称而不是“modelName”时,一切正常,但显然我需要脚本来检查汽车播放器总是在哪里。
4

0 回答 0