UVScroll Script and loading problems.

I have found that sometimes when I load a particular scene in my game it loads quickly with no problems but other times the FPS drops below 1 and it never goes up. I have narrowed the problem down to this UVscroll code (not mine; I forgot who’s it is) I use to make the water in the river flow:

import GameLogic as GL 
cont = GL.getCurrentController() 
own = cont.getOwner()
SPEED = own.speed 
mesh = own.getMesh() 
 
#Aqui defino las diferentes poses 
vert1 = mesh.getVertex(0,0) 
uv1 = vert1.getUV() 
uv1[0] = uv1[0]+SPEED 
vert1.setUV(uv1) 
 
vert2 = mesh.getVertex(0,1) 
uv2 = vert2.getUV() 
uv2[0] = uv2[0]+SPEED 
vert2.setUV(uv2) 
 
vert3 = mesh.getVertex(0,2) 
uv3 = vert3.getUV() 
uv3[0] = uv3[0]+SPEED 
vert3.setUV(uv3) 
 
vert4 = mesh.getVertex(0,3) 
uv4 = vert4.getUV()    
uv4[0] = uv4[0]+SPEED 
vert4.setUV(uv4) 

When I disable this code it works fine every time but I would really like to use this code for the river. Does anyone know why this problem comes up or know of any workarounds for this?
Thanks in advance.

######################
#  UV SCROLL SCRIPT  #
#  by Pepius         #
######################

horizontal = 0
vertical = 1
import GameLogic as GL 
cont = GL.getCurrentController() 
own = cont.getOwner() 
mesh = own.getMesh() 
array = mesh.getVertexArrayLength(0)

#The recomended max. speed is 0.10 and the min. is 0.009
SPEED = own.speed
try:
    DIR = own.dir
except:
    dir = 1
    

for v in range(0,array):
    vert = mesh.getVertex(0,v) 
    uv = vert.getUV() 
    uv[DIR] = uv[DIR]+SPEED 
    vert.setUV(uv)

^Use This

I’m going to have to check into that uv thing, haven’t gotten around to it yet. It looks weird on both scripts because the uv pos never goes back to it’s original, it just keeps getting added to speed. Hard to imagine it. It just looks like there should be a line in there:
if uv > 1:
(tab) uv = 0
or maybe
if uv > 1:
(tab)uv = uv-1

Maybe someone can explain to me why there isn’t. I don’t think uv values are supposed to be greater than 1.

i use the one i’ve posted for all my games and it works fine and doesnt cause much slowdown

I’m just trying to figure out what’s going on there.
From an opengl article I found:

As I mentioned above, non repeating texture coordinates start at 0.0 (in the bottom left hand corner) and finish at 1.0 (in the top right hand corner).

So, I guess numbers above 1 perhaps get ignored. I don’t know, or is it treating this as repeating textures? It would seem it would have to be ignoring, yet values above 1 seem to be legitimate.

scabootssca, thanks for the script. It looks like it allows for a different number of verts besides four as the other one allowed for. It may or may not have fixed my problem because this problem is so random. Sometimes the physics or rasterizer or some other random factor goes way up and the framerate goes to almost nothing.