UPBGE script bug

Hi! Somehow my scripts won’t affect anymore how my object behaves… upbge seens to be using a older version of it. No matter what can’t get it to update.

mah script

import bge
from collections import OrderedDict

from mathutils import Vector

from enum import Enum, auto

class States(Enum):
    IDLE = auto()
    WALKING = auto()
    FALLING = auto()
    ATTACKING = auto()
    DEFENDING = auto()
    

class Character(bge.types.KX_PythonComponent):
    # Put your arguments here of the format ("key", default_value).
    # These values are exposed to the UI.
    args = OrderedDict([
    ])

    def start(self, args):
        self._character = bge.constraints.getCharacter(self.object)
        self._armPivot = self.object.childrenRecursive.get("RigPivot")
        self._armature = self._armPivot.object.childrenRecursive.get("rig")
        
        self.speed = 0.1
        self.state = State.IDLE
        
        self.object.collisionCallbacks.append(self.onCollision)

    def update(self):
        keyboard = bge.logic.keyboard.inputs
        
        if state == State.IDLE or state == State.WALKING or state == State.FALLING:
            updateMovement()
            print("I'm trying to switch!")
            if keyboard[bge.events.FKEY].activated:
                state = State.ATTACKING
                
        elif state == State.ATTACKING:
            pass
        animateMovement()
        
    def updateMovement():
        keyboard = bge.logic.keyboard.inputs
        y = keyboard[bge.events.WKEY].active - keyboard[bge.events.SKEY].active
        x = keyboard[bge.events.DKEY].active - keyboard[bge.events.AKEY].active
        
        if keyboard[bge.events.SPACEKEY].activated:
            self._character.jump()

        vec = Vector([x, y, 0]).normalized() * self.speed
                
        self._character.walkDirection = vec#self.object.worldOrientation * vec
                
            
    def animateMovement():
        direction = self._character.walkDirection
        if self._character.onGround:
            if direction.length != 0:
                self._armPivot.alignAxisToVect(-direction, 1, 0.5)
                self._armPivot.alignAxisToVect([0,0,1], 2, 1)
                self._armature.playAction("KoboldRig|KoboldRig|walk|KoboldRig|walk", 1, 14, blendin=6)
            else:
                self._armature.playAction("KoboldRig|KoboldRig|idle|KoboldRig|idle", 1, 14, blendin=6)
        else:        
            self._armature.playAction("rig|rig|falling|rig|falling", 0, 100, blendin=6)
            
    def onCollision(self, object):
        pass
    

Make a basic script which only does the thing that isn’t working. 9 times out of 10 you’ll find it does actually work, but your logic in the original script just doesn’t activate things as expected.

If it still fails, then show us your very simplified example of the issue and then we can help.

nah, its a bug, not even a print work testUPBGE.blend (686.8 KB)
that brings me to think… is even possible to debug the code?

lots of bugs in your code.

a few examples.

State not defined. - rename class States to State fixes that one

missing self in front of a few function calls
updateMovement() should be self.updateMovement()
and def updateMovement(): should be def updateMovement(self):
there is a few of those

self.object does not exist

check the console for more.

console’s empty:

i fixed all the bugs i could find, here is the code.
(still a few errors do to a missing rig!)

import bge
from collections import OrderedDict

from mathutils import Vector

from enum import Enum, auto

class State(Enum):
    IDLE = auto()
    WALKING = auto()
    FALLING = auto()
    ATTACKING = auto()
    DEFENDING = auto()
    

class Character(bge.types.KX_PythonComponent):
    # Put your arguments here of the format ("key", default_value).
    # These values are exposed to the UI.
    args = OrderedDict([
    ])

    
    def start(self, args):
        self.state = State.IDLE
        self._character = bge.constraints.getCharacter(self.object)
        self._armPivot = self.object.childrenRecursive.get("RigPivot")
        self._armature = self._armPivot.childrenRecursive.get("rig")
        
        self.speed = 0.1
        
        
        self.object.collisionCallbacks.append(self.onCollision)

    def update(self):
        keyboard = bge.logic.keyboard.inputs
        state = self.state
        
        if state == State.IDLE or state == State.WALKING or state == State.FALLING:
            self.updateMovement()
            print("I'm trying to switch!")
            if keyboard[bge.events.FKEY].activated:
                state = State.ATTACKING
                
        elif state == State.ATTACKING:
            pass
        self.animateMovement()
        
    def updateMovement(self):
        keyboard = bge.logic.keyboard.inputs
        y = keyboard[bge.events.WKEY].active - keyboard[bge.events.SKEY].active
        x = keyboard[bge.events.DKEY].active - keyboard[bge.events.AKEY].active
        
        if keyboard[bge.events.SPACEKEY].activated:
            self._character.jump()

        vec = Vector([x, y, 0]).normalized() * self.speed
                
        self._character.walkDirection = vec#self.object.worldOrientation * vec
                
            
    def animateMovement(self):
        direction = self._character.walkDirection
        if self._character.onGround:
            if direction.length != 0:
                self._armPivot.alignAxisToVect(-direction, 1, 0.5)
                self._armPivot.alignAxisToVect([0,0,1], 2, 1)
                self._armature.playAction("KoboldRig|KoboldRig|walk|KoboldRig|walk", 1, 14, blendin=6)
            else:
                self._armature.playAction("KoboldRig|KoboldRig|idle|KoboldRig|idle", 1, 14, blendin=6)
        else:        
            self._armature.playAction("rig|rig|falling|rig|falling", 0, 100, blendin=6)
            
    def onCollision(self, object):
        pass
    

p.s.
using UPBGEv0.2.5a-b2.79Linux64 for testing.

has it worked for you? Because, it still not working here. it was working, but, I’ve removed the code, ran, and pasted it again, then it stoped working.

tried deleting most things, now it gave me an error on a line that’s already deleted…

import bge
from collections import OrderedDict

from mathutils import Vector


class Character(bge.types.KX_PythonComponent):
    # Put your arguments here of the format ("key", default_value).
    # These values are exposed to the UI.
    args = OrderedDict([
    ])

    
    def start(self, args):
        self._character = bge.constraints.getCharacter(self.object)
        print("I'm trying to switch!")
        self.speed = 10
        
  

    def update(self):
        keyboard = bge.logic.keyboard.inputs
        print("I'm trying to switch!")
        if True:
            self.updateMovement()
            
            if keyboard[bge.events.FKEY].activated:
   
    def updateMovement(self):
        keyboard = bge.logic.keyboard.inputs
        y = keyboard[bge.events.WKEY].active - keyboard[bge.events.SKEY].active
        x = keyboard[bge.events.DKEY].active - keyboard[bge.events.AKEY].active
        
        if keyboard[bge.events.SPACEKEY].activated:
            self._character.jump()

        vec = Vector([x, y, 0]).normalized() * self.speed
                
        self._character.walkDirection = vec#self.object.worldOrientation * vec
                
        
            
    def onCollision(self, object):
        pass


test.blend (516.9 KB)

yes the code i posted above works on my machine.

modified_testUPBGE.blend (670.8 KB)

do you remember to reload the component every time you change the code ?
(i assume that’s why it’s there)
image