Help with 2.49 api Python Ray detect & Track to waypoints

Hey guys. Im writing a script using the 2.49 api and I need a little help if you would…

An Always sensor triggers constant motion along the Y-axis, and a Ray sensor triggers this script :


#=========================================== 
# Uses ray to detect collisons with objects 
#=========================================== 
 
# Setup : 
g = GameLogic 
cont = g.getCurrentController() 
 
 
# Get Sensor : 
ray = cont.sensors["sensDetect"]    # Sensor that detects collisions. 
 
# Get Actuator : 
actTrack = cont.actuators["actTrack"]    # Actuator that handles object tracking. 
 
 
# Vars : 
rHit = ray.hitObject 
rDist = ray.range 
rAx = ray.axis 
 
trackTo = actTrack.object 
 
rAx = 0 
rDist = 5.0 
 
 
if ray.positive: 
    print "Just hit: "  
    print rHit 
     
    if rHit == "wp1": 
        trackTo = "wp2" 
        print "Going to: " 
        print trackTo

I’m know my syntax is wrong when it comes to the last bit here, and I’ve tried a few different things to get it working without success. I’m not sure if this is the best approach either, so any advice from those experienced would be helpful.

Thanks.

You’re using the variables as if they were pointers. Python doesn’t have pointers like c++. You’d have to import pointers to use it. Or just code differently.

When you say:
rAx = ray.axis
rAx = 0

You are not setting ray.axis to zero. You are setting rAx to one thing then to another and forgetting about the first value. In python the “=” assignment will simply point your object to the new value instead of changing the value of the pointed object. Same thing is true for rHit, rDist and trackTo. What happens is:
rAx = ray.axis #this points rAx to ray.axis, if you do an id(rAx) and id(ray.axis) they return the same value, meaning they’re pointing to the same place
rAx = 0 #this points rAx to 0, now id(rAx) changed to the same value as id(0)

To fix it you could either change the object directly, ex.: use ray.axis = 0

Or change the proxy like you’re doing, but at the end of your script you pass the value of the proxies back to the objects. ex:
rAx = ray.axis
rAx = 0
… more code
ray.axis = rAx

In your case, your code is simply I would just use ray.axis = 0 instead. Maybe there is a way to set the value of the pointed object instead of using the “=” sign in python, but I personally don’t know how. If someone does, please tell me.

Thanks for your help. I understand what you mean. As you can see I’m very new to this :slight_smile: .