player.try_get_vehicle

a.k.a. player.get_vehicle

When called on a player, this function returns the vehicle that the player is occupying or boarding.

When Bungie and 343i use this function, they often manually clear the object variable they are assigning to before calling the function. That functionality is automated in this Megalo dialect: calling the function with the name get_vehicle will compile in an assignment to no_object before the call, while calling the function with the name try_get_vehicle will not.

This function returns object. Calling this function without storing its return value in a variable is an error.

Example

--
-- Award points for killing an enemy using a sniper rifle while riding in a revenant.
--
for each player do
   alias killer  = global.player[0]
   alias vehicle = global.object[0]
   if current_player.killer_type_is(kill) then
      --
      -- The player is dead.
      --
      global.number[0] = current_player.get_death_damage_type()
      if global.number[0] == enums.damage_reporting_type.sniper_rifle then
         killer  = current_player.get_killer()
         vehicle = killer.get_vehicle()
         if vehicle.is_of_type(revenant) then
            killer.score += 1
         end
      end
   end
end

Notes

See also