I have found the sollution:
attachTrailerToVehicle(train, wagon)
LocoMotive = createVehicle ( 537, 2865, 1340, 12.5 ) -- create a train(freight)
setTimer(
function()
trailer1 = createVehicle ( 569, 2865, 1340, 12.5 ) -- create the first trailer
attachTrailerToVehicle ( LocoMotive, trailer1 ) -- attach them
trailer2 = createVehicle ( 590, 2865, 1340, 12.5 ) -- create the second trailer
attachTrailerToVehicle ( trailer1, trailer2 ) -- attach them
trailer3 = createVehicle ( 569, 2865, 1340, 12.5 ) -- create the third trailer
attachTrailerToVehicle ( trailer2, trailer3 ) -- attach them
end, 50, 1)
I have created a train with 3 wagons.