Need help understanding this code

This code is from the blender game kit 2.0 (sub racer) it is used to make the bullets faster then the sub. I get everything, except for a few unexplained additions that are not notated in the book for why they are there. I just know removing these parameters does not initiate the add object actuators. Here is the code, and I’ll explain what I need help with.

Gun script

This script takes the velocity of the ship into account for firing the cannons

also uses instantAddObject to prevent 1 frame lag of the Add Object Actuator

import GameLogic

cont = GameLogic.getCurrentController()
me = cont.getOwner()

fire = cont.getSensor(“Fire”)
g1 = cont.getActuator(“G1”)
g2 = cont.getActuator(“G2”)

if fire.isPositive():
ys = me.getLinearVelocity(1)[1]
g1.setLinearVelocity(0,30+ys,0)
g2.setLinearVelocity(0,30+ys,0)
g1.instantAddObject()
g2.instantAddObject()

As I said, I get all of this except for a few parts of this, " ys = me.getLinearVelocity(1)[1]" line. I know it assigns the velocitry of the ship to ys, which is later used to add to the initial force of the bullet, but when I find “getLinearVelocity()” it does not explain ‘(1)[1]’ what that details I have no clue, it looks like it activates the call and starts at array point 1, but I don’t I understand this very much.

Anyone think they could break this down a bit more for me?

getLinearVelocity() can be called with or without a boolean (true/false, aka 1/0) argument. It defaults to 0, which returns “global” velocity… ie in relation to global axis. With a 1 passed in, it’ll return “local” velocity.

getLinearVelocity() also returns a list type object. Lists have multiple entries, and you access those entries with [number]. getLinearVelocity()[0] the the X axis speed, getLinearVelocity()[1] is the Y axis speed… etc.

Hope that helps!