Hi, I have created a program that follows a line blitted on a surface called 'screen'. I have created a function in a different file to do so and have imported it into my main file like so:

from Follow_Ground import Follow_Ground

The code in the file 'Follow_Ground.py' looks like this (only part of the code):

import pygame
from pygame.locals import *
pygame.init()

#   Follow_Ground(Different input options1,and2,Xposition,Original Y pos.,final return target value)
def Follow_Ground(KeyINP1,KeyINP2,Xpos,YposOR):
    #global variables
    global VARtarget
    VARtarget = 0
    print 'hi'
    for event in pygame.event.get():
        if (event.type == KEYDOWN):
            if (event.key == KeyINP1) or (event.key == KeyINP1):
                color = screen.get_at((Xpos, YposOR))
                if color == (0, 0, 0, 255) or color == (1, 0, 0, 255) or color == (0, 1, 0, 255) or color == (0, 0, 1, 255) or color == (1, 1, 0, 255) or color == (1, 0, 1, 255) or color == (1, 1, 1, 255):
                    VARtarget = 12

I see that I want to read a pixel color from the other main file, but since the surface 'Screen' is created and managed in the other file, I really don't know how to make this file above (Follow_Ground.py) recognize that it needs to look at the surface, 'screen'. I am wondering if anyone knows how to transfer this info from the main file over to 'Follow_Ground.py'.

Thanks, 26bm

My suggestion is to make it a global file in the Main file and just input it into the class or function when you call it. Add it to the list of items asked for when running the program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.