Getting an output from blender

Good morning/evening

This is question for help, I didn’t do the scripts myself

I’m trying to apply this tutorial : https://www.youtube.com/watch?v=jOeGyqOr66E&index=7&list=PLD2F1C5F312A669FF

In general the tutorial sounds like creating a calculator in game engine

When I press “Enter” or “Enter in numpad” the number I have entered in miles should be converted immediately to km.

Instead of converting the number, the game just show letter “E” as I press “Enter in numpad”. When pressing “Enter” nothing happens.


The scripts I used are shown in .blend file that’s attached.

I have modified Text.py and named the script with the modification Text 2.py, even though it didn’t yet

3.blend (634 KB)

Try

keyboard.events[bge.events.ENTERKEY]

To sense the enter key

http://www.zoo-logique.org/3D.Blender/scripts_python/BPY/bge.events.html

Do you mean like this:


?

I tried putting it like this, but still doesn’t work

Maybe something like this (see above file example for download):

import bgefrom bge import logic




# Do the all keys thing
import bge


co = bge.logic.getCurrentController()
# 'Keyboard' is a keyboard sensor
sensor = co.sensors["Keyboard"]


scene = logic.getCurrentScene()
object1 = scene.objects["Text"]
object2 = scene.objects["Answer"]




def draw_text(string):
    if(string == "BACKSPACEKEY"):
         
        return -1
    else:
        return 1




for key,status in sensor.events:
    # key[0] == bge.events.keycode, key[1] = status
    if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
        string = bge.events.EventToString(key)
        
        if(string == "PADENTER"):
            #write your KM conversion here
            object2.text = "The answer is"
        else:
            print(string)
            
            if(draw_text(string) == -1):
                f = object1['prop'] 
                #delete the last character
                f = f[:-1]
                
                object1['prop'] = f
                
                print(len(f))
                object1.text = f
            else:
                object1['prop'] += string[3]
                object1.text = object1['prop']

sense-keys-2.blend (642 KB)

GREAT, it worked !

interesting the way your script simplified all the process in few steps

Thanks a lot =)

No worries, I’m sure I did a few things wrong, but just learning python since this week :wink:

No way! I’ve started before you by months, but with many interruptions here and there, and without connecting it with blender.

what are you learning sources?