3
$\begingroup$

Screen 1
When I hover over and click the exit button it works, but when I am doing the same thing with the start button it shows an error:

line 9, in main  KeyError: 'requested item "startGame" does not exist'

Screenshot 1

Screen 2
In the second screen, when I deactivate all sensors and actuator of the exit button, the start button is working properly.

Please help me.

Screenshot 2

$\endgroup$
0
$\begingroup$

I strongly suggest to separate hover from activating. This makes the implementation much simpler.

Hover

There are two different designs to achieve hover:

Individual Hover

Each objects handles the hover by itself. This is fine when each object has a different way to present hover

E.g.

Mouse Over Sensor -> AND -> Action Actuator Mode:Flipper Action: Hover.Action

Hover Controller

One object the Hover Controller handles all hover and performs the according actions. Due to it's dynamic behavior you need to Python to do that.

Mouse Over Any Sensor -> Python

import bge

COLOR_HOVERRED = [1, 0, 0, True]

controller = bge.logic.getCurrentController()
storage = controller.owner

sensors = controller.sensors
mouseSensor = sensors[0]

if mouseSensor.positive:
    hoverredObject = mouseSensor.hitObject
    storage["last hoverred"] = hoverredObject

    storage["original color"] = hoverredObject.color.copy()
    hoverredObject.color = COLOR_HOVERRED
else:
    lastHoverred = storage.get("last hoverred")

    if lastHoverred:
        lastHoverred.color = storage["original color"]

This code is based on your sample. When you want to hover certain objects only you can setup a filter property (e.g. "hoverable") at the mouse sensor and give each Object an according property "hoverrable".

Button Click

The button click is very simple and you do not necessarily need Python

mouse over sensor + mouse click sensor -> AND -> actuator

$\endgroup$
  • $\begingroup$ thanks for support problem has been resolved but another problem generated and i am trying to resolve that $\endgroup$ – Aman Singh Nov 23 '17 at 15:16
0
$\begingroup$

Mouse over text does not work, instead use a plane invible and parent it to the text (child), to make parent use Alt+P.

enter image description here

The plane needs to be an actor to be detected.

enter image description here

Use the logic on the planes:

enter image description here

And to change the color use cont.owner.children[0].color = [1,1,1,true].

When you use module execution mode it pass the controller to the function.

#Note that there is no imports

def start(cont):
    l_click = cont.sensors['MouseStart']
    m_over = cont.sensors['MouseStart1']
    game_actuator = cont.actuators['startGame']
    if l_click.positive and m_over.hitObject:
        cont.activate(game_actuator)

def exit(cont):
    l_click = cont.sensors['MouseExit']
    m_over = cont.sensors['MouseExit1']
    game_actuator = cont.actuators['Game']
    if l_click.positive and m_over.hitObject:
        cont.activate(game_actuator)
$\endgroup$
  • $\begingroup$ thanks for support problem has been resolved but another problem generated and i am trying to resolve that $\endgroup$ – Aman Singh Nov 23 '17 at 15:18

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.