Community Forum

for k, v in pairs(VehicleTypeUtil.vehicleTypes)

Forum Overview >> Scripting

CategoryScripting
Created27.11.2018 06:17


Anthony Roark (iwasthere83) 27.11.2018 06:17
Running into an error: register.lua:10: attempt to index global 'VehicleTypeUtil' (a nil value)

Could Giants please help point me in the right direction?

GPS_Register = {};
GPS_Register.dir = g_currentModDirectory;
addModEventListener(GPS_Register);

function GPS_Register:loadMap()
if self.GPS_register_firstRun == nil then
self.GPS_register_firstRun = false;
print("--- loading GPS mod V5.2.0 --- (by upsidedown & Monax Сompany (c))")

for k, v in pairs(VehicleTypeUtil.vehicleTypes) do
if v ~= nil then
local allowInsertion = true;
for i = 1, table.maxn(v.specializations) do
local vs = v.specializations[i];
if vs ~= nil and vs == SpecializationUtil.getSpecialization("steerable") then--
local v_name_string = v.name
local point_location = string.find(v_name_string, ".", nil, true)
if point_location ~= nil then
local _name = string.sub(v_name_string, 1, point_location-1);
if rawget(SpecializationUtil.specializations, string.format("%s.GPS", _name)) ~= nil then
allowInsertion = false;
end;
end;

Gtx | Andy (GtX_Andy) 28.11.2018 00:56
First `VehicleTypeUtil` is a depreciated value now.

Second no one here or Giants themselves is going to help you convert a script written by someone else as this is wrong.

Do the right thing and wait for the Author to convert it.

Jeffery Lind (Unknown) 28.11.2018 01:28
I’m pretty sure Upsidesdown did not give you permission to modify his code. You should delete this post. People are not fond here if others taking their work and modifying it.

Anthony Roark (iwasthere83) 28.11.2018 02:14
Well you guys are right honestly, it was bad form. How do I delete a post?

Espen K. (estyx) 29.11.2018 18:05
As Andy mentioned, VehicleTypeUtil is no more.
You now have to use the global variable: g_vehicleTypeManager

In order to get a list of all vehicle types:
result = g_vehicleTypeManager:getVehicleTypes()

If you want to get a specific vehicle type:
result = g_vehicleTypeManager:getVehicleTypeByName('fuelTrailer')

Same with SpecializationUtil, it's now g_specializationManager

result = g_specializationManager:getSpecializations()

result = g_specializationManager:getSpecializationByName('...')


Note: Log in to post. Create a new account here.