kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

Script not working with Python 2.7

Opened this issue · 0 comments

commented

Hi,
for a school project wanted to to some BFS style landings and tried krpc with Infernal Robotics and a python script to build it. Unfortunatly, my script is not working at all.

I can run it and krpc get a popup that a scripts want to connect, but if I run it it says "RESTART" and thats all. As if it never get over the initial connection with krpc. Can somebody please help me?

My setup:

  • Windows 10
  • KSP-Version: Steam, 1.4.2
  • CKAN 1.25.4
  • Kronal Vessel Viewer 0.0.9.6 with Click Through Block 0.1.6.7 and Toolbar Controller 0.1.6.16 (installed with CKAN)
  • KRPC 0.4.8
  • Kerbal Engineer Redux 1.1.4.10
  • Infernal Robotics - Next 3.0.0.0 beta3 for KSP 1.4.2
# Import benötigter Module  
import krpc  
  
# Aufbau der Verbindung zu KRPC und Auswahl der aktiven Raumfähre  
verbindung = krpc.connect(name='Alpha ')  
faehre = verbindung.space_center.active_vessel  
  
# Anlegen von Variablen um die Servos zur Steuerung ansprechen zu können  
lb = verbindung.infernal_robotics.servo_with_name(faehre,"LinkerBug")  
rb = verbindung.infernal_robotics.servo_with_name(faehre,"RechterBug")  
lh = verbindung.infernal_robotics.servo_with_name(faehre,"LinkesHeck")  
rh = verbindung.infernal_robotics.servo_with_name(faehre,"RechtesHeck")  
  
# Ausgabe der aktuellen Position der Servos  
print lb.name + " " + str(lb.position)  
print rb.name + " " + str(rb.position)  
print lh.name + " " + str(lh.position)  
print rh.name + " " + str(rh.position)  
  
# Anlegen von Variablen für die Servopositionen, setzten auf 0  
lbp = 0  
rbp = 0  
lhp = 0  
rhp = 0  
  
# Überprüfen ob die Bremse aktiviert wurde  
# Wurde die Bremse aktiviert, 
# wird der 'Servo-Modus' gestartet, der erlaubt, über die 
# Spielsteuerung die Seitenleitwerke mithilfe der Servos zu kontrollieren  
bremse = vessel.control.brakes  
servoModus = False  
while(1):  
    if vessel.control.brakes:  
        if bremse != vessel.control.brakes:  
            rhp = -45  
            lhp = 45  
            rbp = -45  
            lbp = -45  
            rh.move_to(rhp,5)  
            lh.move_to(lhp,5)  
            rb.move_to(rbp,5)  
            lb.move_to(lbp,5)  
  
            bremse = vessel.control.brakes  
            servoModus = True  
  
    else:  
        if bremse != vessel.control.brakes:  
            rh.move_to(0,5)  
            lh.move_to(0,5)  
            rb.move_to(0,5)  
            lb.move_to(0,5)  
  
            bremse = vessel.control.brakes  
            servoModus = False  
  
# Bewegungen entlang der Roll-Nick-Gier-Winkel  
    if servoModus:  
        neigen = vessel.control.up  
        bewegung = False  
        if(neigen != 0):  
            bewegung = True  
            if(neigen < 0):  
                lbp = lbp + 0.5  
                rbp = rbp - 0.5  
                lhp = lhp - 0.5  
                rhp = rhp - 0.5  
            if(neigen > 0):  
                lbp = lbp - 0.5  
                rbp = rbp + 0.5  
                lhp = lhp + 0.5  
                rhp = rhp + 0.5  
          
        gieren = vessel.control.right  
        if(gieren != 0):  
            bewegung = True  
            if(gieren > 0):  
                lbp = lbp + 0.1  
                rbp = rbp + 0.1  
                lhp = lhp - 0.1  
                rhp = rhp + 0.1  
            if(gieren > 0):  
                lbp = lbp - 0.5  
                rbp = rbp - 0.5  
                lhp = lhp + 0.5  
                rhp = rhp - 0.5  
  
        rollen = vessel.control.forward  
        if(rollen != 0):  
            bewegung = True  
            if(rollen > 0):  
                lbp = -45  
                rbp = -45  
                lhp = 45  
                rhp = -45  
                if(rollen < 0):  
                    lbp = 0  
                    rbp = 0  
                    lhp = 0  
                    rhp = 0  
      
            if bewegung:  
                rh.move_to(rhp,1)  
                lh.move_to(lhp,1)  
                rb.move_to(rbp,1)  
                lb.move_to(lbp,1)

Can someone please help me figure it out?

Thanks

K.