how can I tell the function, to look into and take the value of a specific index of a list, whose values get updated?

I’ve created a class, whose object falcon_vectors holds each vector I add to it and the class is also responsible for updating the vectors coordinates i.e. in main update function I just call falcon_vectors.update(). They each start at the same origin point, but their end points (x2, y2) differ depending on what kind of vector they are (e. g. horizontal velocity vector, vertical velocity vector, both).

My problem is: when I pass a list into the function (f9.v_m_s … the first vector consisting of both the horizontal and the vertical component), it displays the vector properly, since (I believe) instead of passing the initial coordinates 0;0, python passes the entire list and later in the function, when the function looks into the list, it finds out, that the coordinates are no longer 0;0, but for example 100,100 so the vector displays properly

But as soon as I want to create just the horizontal component of that vector i.e. I input just the horizontal x value of that vector and leave the vertical value as 0, (I believe) that python passes just the initial coordinates 0;0, meaning, that the update function always updates x2 and y2 to 0;0 instead of the current, updated coordinates, so the vector doesn’t display at all, since the line’s end point matches its staring point

so how can I tell the update function, to look into the first index of f9.v_m_s list every time it updates the vector’s coordinates?

class FalconVectors:
    def __init__(self) -> None:
        self.vectors = []

    def new_vector(self, coordinates, color, visual_enlargement_factor):
        vector = {
            "pyglet_component": pyglet.shapes.Line(0,0,0,0,3,color,sw_batch),
            "coordinates": coordinates,
            "visual_enlargement_factor": visual_enlargement_factor
        }
        self.vectors.append(vector)

    def update(self):
        for vector in self.vectors:
            vector["pyglet_component"].x = falcon_screen_location_point_px.x
            vector["pyglet_component"].y = falcon_screen_location_point_px.y
            vector["pyglet_component"].x2 = falcon_screen_location_point_px.x + m_into_px(vector["coordinates"][0]) * vector["visual_enlargement_factor"]
            vector["pyglet_component"].y2 = falcon_screen_location_point_px.y + m_into_px(vector["coordinates"][1]) * vector["visual_enlargement_factor"]

falcon_vectors = FalconVectors()
#f9.v_m_s = [0, 0] <-- later gets updated
falcon_vectors.new_vector(f9.v_m_s, RED, 500) #velocity vector
falcon_vectors.new_vector((f9.v_m_s[0], 0), BLUE, 500) #horizontal velocity vector

btw, m_into_px just transforms meters into pixels

I’ve managed to solve it by adding two booleans to each vector, which determine, which component (horizontal, vertical or both) should be added to the vector’s origin point.

But the question remains: how can I pass the variable itself into the function instead of the number the variable is pointing at?

class FalconVectors:
    def __init__(self) -> None:
        self.vectors = []

    def new_vector(self, coordinates, access_0, access_1, color, visual_enlargement_factor):
        vector = {
            "pyglet_component": pyglet.shapes.Line(0,0,0,0,3,color,sw_batch),
            "coordinates": coordinates,
            "access_0": access_0,
            "access_1": access_1,
            "visual_enlargement_factor": visual_enlargement_factor
        }
        self.vectors.append(vector)

    def update(self):
        for vector in self.vectors:
            vector["pyglet_component"].position = falcon_screen_location_point_px.position
            vector["pyglet_component"].x2 = falcon_screen_location_point_px.x
            vector["pyglet_component"].y2 = falcon_screen_location_point_px.y
            if vector["access_0"]:
                vector["pyglet_component"].x2 += m_into_px(vector["coordinates"][0]) * vector["visual_enlargement_factor"]
            if vector["access_1"]:
                vector["pyglet_component"].y2 += m_into_px(vector["coordinates"][1]) * vector["visual_enlargement_factor"]

falcon_vectors = FalconVectors()
#f9.v_m_s2 = [0, 0] <-- later gets updated
falcon_vectors.new_vector(f9.v_m_s2, True, True, RED, 500) #velocity vector
falcon_vectors.new_vector(f9.v_m_s2, True, False, BLUE, 500) #horizontal velocity vector

New contributor

Tofu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật