Ai script, slighly brokeded...

I am making my Ai for the Blender Game Competition. I scripted it all myself, but its not quite working yet. I show the script below and a .blend.

Situation :
The script tells the Guard to walk if “random_prop” is 1 or stand idle if “random_prop” is 2. But all he does is stand animation, but moves forward as if he were walking.

Uber embarrassment :o

Scripts :

import random
import Mathutils as MT

cont = GameLogic.getCurrentController()
own = cont.owner

own["random_prop"] = int(MT.Rand(1, 2))

i_see_you = cont.getSensor("see_player")
player_right = cont.getSensor("right")
player_left = cont.getSensor("left")
stop_turn = cont.getSensor("stop_turn")

Patrol = cont.getActuator("MoveAround")
Idle = cont.getActuator("Idle")
mes_patr_send = cont.getActuator("Patrol_Armature")
mes_idle_send = cont.getActuator("Idle_Armature")
turn_left = cont.getActuator("Turn_left")
turn_right = cont.getActuator("Turn_right")

rotation = [ 0.0, 0.0, 0.1]

def roamer() :
    cont.activate(Patrol)
    cont.activate(mes_patr_send)
    
def idle() :
    cont.activate(Idle)
    cont.activate(mes_idle_send)
    
def attack() :
    if player_left.isPositive:
        own.applyRotation( rotation, True)
        
    if player_right.isPositive:
        cont.activate(turn_right)
        
    
    
if own["random_prop"] == 1 :
    roamer()
    
if own["random_prop"] == 2 :
    idle()
    
if i_see_you.isPositive :
    attack()

and for the Armature :

import random
import Mathutils as MT

cont = GameLogic.getCurrentController()
own = cont.owner

mes_patr_receive = cont.getSensor("Patrol_AI")
mes_idle_receive = cont.getSensor("Idle_AI")

walk = cont.getActuator("Walk")
stand = cont.getActuator("Stand")
attack = cont.getActuator("attack_Armarture")

def roamer() :
    cont.activate(walk)
    
def idle() :
    cont.activate(stand)
    
def attack():
    cont.activate(attack)
    
if mes_patr_receive.isPositive :
    roamer()
    
if mes_idle_receive.isPositive :
    idle()
    

Please help. Thanks. And if there is anything else that could be fixed or improved, please explain it, this is my first Ai script:o.

.blend

W, S, A, D move
Q to add Gaurd

and if u want to see the Gaurd setup, it is on Layer 6 on the second row ( If that makes sense:confused:).

Thanks in advance.

the blend file is nowhere to be found :confused:

LOL
though thats kinda of what im looking for with ai
so thanks

Yeah, sorry about that. I am still trying to upload it. For some reason its 42mb, and im trying to upload it to mediafire but it keeps failing for some reason.

rain check? :o

Deactivate the other actuators, so:

def roamer():
    cont.deactivate(stand)
    cont.deactivate(attack)
    cont.activate(walk)

Do the same for the other 2 functions.

Action actuators should have a priority property, if two are activated at once and the actions conflict (as in both use the same bones) the actuator with the higher priority runs. I assume that if all actuators have the same priority perhaps the actuator highest in the list gets priority.

Ok, thanks i’ll try that. I’ll be back later with the results.

edit : Well, that problem is fixed. But now it wont stand still at all. thanks btw

import random
import Mathutils as MT

cont = GameLogic.getCurrentController()
own = cont.owner

mes_patr_receive = cont.getSensor("Patrol_AI")
mes_idle_receive = cont.getSensor("Idle_AI")

walk = cont.getActuator("Walk")
stand = cont.getActuator("Stand")
attack = cont.getActuator("attack_Armarture")

def roamer() :
    cont.activate(walk)
    cont.deactivate(stand)
    cont.deactivate(attack)
    
def idle() :
    cont.activate(stand)
    cont.deactivate(walk)
    cont.deactivate(attack)
    
def attack():
    cont.activate(attack)
    cont.deactivate(stand)
    cont.deactivate(walk)
    
if mes_patr_receive.isPositive :
    roamer()
    
if mes_idle_receive.isPositive :
    idle()
    

the error in the console reads :
File: “Armature_AI”, line 17, in roamer
ValueError : ‘<function attack at 0x031A36F0>’ not in this python controllers actuator list.

anyone got that one?

The error indicates that the actuator is not connected to the controller, which makes absolutely no sense at all as you referenced the actuator from the controller in the first place. Not sure what the problem is.

could i achieve this method a different way?