Jump to content

what is the difference


Ihnify

Recommended Posts

what is the difference

example #1

Fuel = {
    id = { }; --
    
     object = {
        {611.23419189453, 1694.9637451172, 6.5105047225952},
        {607.91522216797, 1699.8511962891, 6.5105137825012},
        {2210.05859375, 2474.6975097656, 10.33863067627},
        {2200.486328125, 2476.20703125, 10.338635444641},
        {2114.7475585938, 928.62805175781, 10.338633537292},
        {2114.5134277344, 911.67749023438, 10.33864402771},
        {1382.2032470703, 461.80364990234, 19.623880386353},
        {-98.42310333252, -1166.6186523438, 2.0666558742523},
        {-85.406776428223, -1171.2337646484, 1.7744096517563},
        {1005.0834350586, -933.74597167969, 41.69800567627},
        {1004.5383300781, -940.85437011719, 41.665897369385},
        {1938.9345703125, -1772.6749267578, 12.904432296753},
        {1945.3464355469, -1772.1834716797, 12.906016349792},
    };
  
    init = function ( )
        addEventHandler("onPlayerVehicleEnter", root, Fuel.playerVehicleEnterFuel)
        addEventHandler("onPlayerVehicleExit", root, Fuel.playerVehicleExitFuel)
        addEventHandler("setVehicleFuel", root, Fuel.setVehicleFuel)
    
        for index in pairs(Fuel.object) do
            Fuel.id[index] = createMarker( )
        end
    end;
     
    getID = function ( theVehicle )
        -- code
    end;
    setVehicleFuel = function ( theVehicle, fuel )
        -- code
    end;
  
    playerVehicleExitFuel = function ( theVehicle, seat ) 
        -- code
    end;
  
    playerVehicleExitFuel = function ( theVehicle, seat ) 
        -- code
    end
}
addEventHandler('onResourceStart', resourceRoot, Fuel.init)
and use example
Fuel.getID(theVehicle) in another server file
for example, as I understand it, the global variable fuel is created, is it good or bad? If used like this often
 
or example #2
and here a local variable is created
getID(theVehicle) in another server file
 
local fuel = {
    id = { },
    
    object = {
      {611.23419189453, 1694.9637451172, 6.5105047225952},
      {607.91522216797, 1699.8511962891, 6.5105137825012},
      {2210.05859375, 2474.6975097656, 10.33863067627},
      {2200.486328125, 2476.20703125, 10.338635444641},
      {2114.7475585938, 928.62805175781, 10.338633537292},
      {2114.5134277344, 911.67749023438, 10.33864402771},
      {1382.2032470703, 461.80364990234, 19.623880386353},
      {-98.42310333252, -1166.6186523438, 2.0666558742523},
      {-85.406776428223, -1171.2337646484, 1.7744096517563},
      {1005.0834350586, -933.74597167969, 41.69800567627},
      {1004.5383300781, -940.85437011719, 41.665897369385},
      {1938.9345703125, -1772.6749267578, 12.904432296753},
      {1945.3464355469, -1772.1834716797, 12.906016349792},
    }
}

function initFuel ( )
    for index in pairs(fuel.object) do
        fuel.id[index] = createMarker()
    end
end
addEventHandler( "onResourceStart", resourceRoot, initFuel)

function getID ( theVehicle )
    return fuel.id[number] -- example
end

function setVehicleFuel ( theVehicle, fuel )
    -- code
end
addEventHandler("setVehicleFuel", root, setVehicleFuel)

function playerVehicleEnterFuel ( theVehicle, seat )
    -- code
end
addEventHandler("onPlayerVehicleEnter", root, playerVehicleEnterFuel)

function playerVehicleExitFuel ( theVehicle, seat ) 
   -- code
end
addEventHandler("onPlayerVehicleExit", root, playerVehicleExitFuel)

 

Edited by Ihnify
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...