-1
$\begingroup$

I am new to Blender, so please help me to provide two inputs in Blender game as in dijkstra algorithm. I need one input for source and another for destination to tell the distance between them.

When I am giving input in source then the text field of destination is field automatically with same value as of source so the generated output is 0 at every time.

Logic-bricks of source enter image description here

Logic-bricks of destination
Screenshot

Logic-bricks of distance
Screenshot

$\endgroup$
1
$\begingroup$

Note that i assing the values to a persist in bge.logic attribute, also if you have 2 messages sensor waiting for the same subject you will recive always the same value, to have 2 inputs you need that only 1 state active as input so in state_1 only text_1 has a keyboard sensor and text_2 has no sensors while in state 2 the the text_2 has a keyboard sensor ans text_1 has no sensors, to change the state use a keyboard sensor key RETURN+and controller+state actuator to change the states.

Option 1:

enter image description here

from bge import logic

scene = logic.getCurrentScene()
cont = logic.getCurrentController()

if not hasattr(logic,'value1'):
    logic.value1 = int(cont.sensors['Message'].bodies[0])
elif not hasattr(logic,'value2'):
    logic.value2 = int(cont.sensors['Message.001'].bodies[0])

scene.objects['result']['Text'] = logic.value1 + logic.value2

enter image description here enter image description here enter image description here

Option 2: #######################################################

enter image description here

from bge import logic

scene = logic.getCurrentScene()

def waiting_inputs(controller):
    if not hasattr(logic,'value1'):
        scene.objects['hint']['Text'] = 'Enter value 1:'
        input = scene.objects['input']
        logic.value1 = int(input['Text'])
        input['Text'] = 'Here'
        return
    elif not hasattr(logic,'value2'):
        scene.objects['hint']['Text'] = 'Enter value 2:'
        input = scene.objects['input']
        logic.value2 = int(input['Text'])
    else:
        showOutput()

def showOutput():
    scene.objects['result']['Text'] = logic.value1 + logic.value2

enter image description here

enter image description here

Option 3: #######################################################

from bge import logic

scene = logic.getCurrentScene()
cont = logic.getCurrentController()

if not hasattr(logic,'value1'):
    logic.value1 = int(cont.sensors['Message'].bodies[0])
elif not hasattr(logic,'value2'):
    scene.objects['hint']['Text'] = 'Enter value 2:'
    logic.value2 = int(cont.sensors['Message'].bodies[0])

scene.objects['result']['Text'] = logic.value1) + logic.value2

enter image description here

enter image description here

$\endgroup$
  • $\begingroup$ thanks for your support and time which you spend to solve this problem $\endgroup$ – Aman Singh Nov 23 '17 at 14:50
  • 1
    $\begingroup$ If this totally answer your question please consider accepting it as an answer. $\endgroup$ – Strapicarus Dec 25 '17 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.