Hello!
I made a script for an interactive python console in bge (like many others before)
and its working somehow,
but when i want to assign something to a variable it gives me a syntax error
File “<string>”, line 1
own[“test”] = 1
or
Python script error - object ‘Text’, controller ‘Python’:
Traceback (most recent call last):
File “Console”, line 172, in <module>
File “Console”, line 34, in main
File “<string>”, line 1
a = 1
^
SyntaxError: invalid syntax
print(“hello”)
and simple math works
can somebody help me out
her is the code
import bge
def main():
cont = bge.logic.getCurrentController() own = cont.owner keyboard = cont.sensors["Keyboard"] if alphabet not in own: alphabet(own,0,32) if keyboard.positive: if [125,2] in keyboard.events: modif = 2 elif [129,2] in keyboard.events: modif = 1 else: modif = 0 for x in keyboard.events: if x[1] == 1: print (keyboard.events) current_key = x[0] if current_key in [133,13]: if current_key == 13: command = str (own["Text"]) own["Text"] = "" own["Text"] = str(eval(command)) if current_key == 133: backspace(own) if current_key == 125: modif = 2 try: own["Text"] += alphabet(own,modif,current_key) except TypeError: if own["Text"] is None: own["Text"] = "" else: own["Text"] = str (own["Text"]) raise
def alphabet(own,modif,input):
own[“alphabet”] = {
32 :" “,
45:”-“,
136 : “#”,
131:” “,
46:”.",48:"0",49:"1", 50:"2",51:"3", 52:"4",53:"5", 54:"6",55:"7", 56:"8",57:"9", 97:"a" ,98:"b", 99:"c",100:"d", 101:"e",102:"f", 103:"g",104:"h", 105:"i",106:"j", 107:"k",108:"l", 109:"m",110:"n", 111:"o",112:"p", 113:"q",114:"r", 115:"s",116:"t", 117:"u",118:"v", 119:"w",120:"x", 121:"y",122:"z", 42:"*",157:"/", 161:"+",159:"-", } own["alphabetShift"] ={ 45:"_", 136 : "'", 48:"=",49:"!", 50:"\"",51:"§", 52:"$",53:"%", 54:"&",55:"/", 56:"(",57:")", 97:"A" ,98:"B", 99:"C",100:"D", 101:"E",102:"F", 103:"G",104:"H", 105:"I",106:"J", 107:"K",108:"L", 109:"M",110:"N", 111:"O",112:"P", 113:"Q",114:"R", 115:"S",116:"T", 117:"U",118:"V", 119:"W",120:"X", 121:"Y",122:"Z", 42:"*",157:"/", } own["alphabetAlt"] ={ 32 :" ", 45:"-", 136 : "#", 131:" ", 48:"}",49:"¹", 50:"²",51:"³", 52:"¼",53:"½", 54:"¬",55:"{", 56:"[",57:"]", 97:"æ" ,98:"“", 99:"¢",100:"ð", 101:"€",102:"đ", 103:"ŋ",104:"ħ", 105:"→",106:"̣", 107:"ĸ",108:"ł", 109:"µ",110:"”", 111:"ø",112:"þ", 113:"@",114:"¶", 115:"ſ",116:"ŧ", 117:"↓",118:"„", 119:"ł",120:"«", 121:"»",122:"←", 42:"*",157:"/",
} if modif == 0 : if input in own["alphabet"]: return (own["alphabet"][input]) else: return ("") if modif == 1 : if input in own["alphabetShift"]: return (own["alphabetShift"][input]) else: return("") if modif == 2 : if input in own["alphabetAlt"]: return (own["alphabetAlt"][input]) else: return("")def execute(own):
pass
def backspace(own):
text = str (own[“Text”])
length = len(text)
if length >= 1:
text = text[0:length-1]
own[“Text”] = text
main()
Thanks in advance!
TB