Trying to create custom 3d model exporter, getting weird values

Hello, I am trying to create a script that exports data from a 3d model into a txt file, however I cannot seem to get the indices properly, nor do I get the right uv coordinates. I’ve tested the model on an openGl app I’m making, and the indices and uvs are screwed up. Forgive my horrible python coding skills, I’m still practicing. I have a hard time understanding the difference between loop indices and uv indices.

Here is my code:

import bpy
import struct
import os

class vertice:
    xPosition = 0.000000
    yPosition = 0.000000
    zPosition = 0.000000
    u = 0.000000
    v = 0.000000
    
vertexList = []
indices = []

outFile = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "wb")
mesh = bpy.data.objects["Cube"]
uvMesh = mesh.data

for poly in mesh.data.polygons:
    print("Polygon index: %d, length: %d" % (poly.index, poly.loop_total))
    for loop_index in range(poly.loop_start, poly.loop_start + poly.loop_total):
        print("    Vertex: %d" % mesh.data.loops[loop_index].vertex_index)

for polygon in mesh.data.polygons:
    for loop_index in range(poly.loop_start, poly.loop_start + poly.loop_total):
        vert = vertice()
        index = mesh.data.loops[loop_index].vertex_index
        #print(mesh.data.vertices[vertz].co.x)
        vert.xPosition = mesh.data.vertices[index].co.x
        vert.yPosition = mesh.data.vertices[index].co.y
        vert.zPosition = mesh.data.vertices[index].co.z
        vert.u = uvMesh.uv_layers[0].data[index].uv.x
        vert.v = uvMesh.uv_layers[0].data[index].uv.y
        vertexList.append(vert)
        length = 0
        for index in vertexList:
            length = length + 1
            int(length)
        indices.append(length)

strin = bytes('SOLID3D1', 'utf-8')
dataH = struct.pack('8s', strin)
outFile.write(dataH)

vSize = 0
iSize = 0

for verts in vertexList:
    vSize = vSize + 1
int(vSize)
dataVSize = struct.pack('I', vSize)

for indice in indices:
    iSize = iSize + 1
int(iSize)
dataISize = struct.pack('I', iSize)
outFile.write(dataVSize)
outFile.write(dataISize)
for verts in vertexList:
      
    print(verts.xPosition)
    datax = struct.pack('f', verts.xPosition)
    datay = struct.pack('f', verts.yPosition)
    dataz = struct.pack('f', verts.zPosition)
    datau = struct.pack('f', verts.u)
    datav = struct.pack('f', verts.v)
    outFile.write(datax)
    outFile.write(datay)
    outFile.write(dataz)
    outFile.write(datau)
    outFile.write(datav)
    
for indice in indices:
    datai = struct.pack('I', indice)
    outFile.write(datai)
outFile.close()

check here, might be useful:

Exporting UV coordinates