0
$\begingroup$

So I have a HUD scene that has a list of duplicate objects from the main scene, and I want to be able to click the list with the mouse and it toggle selects the object, highlighting it, de-selecting any other objects that were selected, and the main scene when I click that object it spawns the selected object. Think real basic lego game, which is not far off.

Right now the spawner's need to be mouse-over and press a number 1 through 4 to spawn the object that is assigned to that number. But I want to select an object from a menu that can hold a lot more objects than keys.

I have two scenes: HUD and Scene.

HUD has a menus with duplicate objects in the bottom menu to select from.

Scene has a series of tiles that highlight when moused over.

I want to select and object from the menu, highlighting it, deselecting any previously selected object, and from there click on a tile to spawn that object.

Edit:

Scene:
  -obj 1
  -tile
HUD:
  -obj 1

When I toggle select -obj 1 from the HUD (menu), I want it to send a signal to -tile that is a string of "-obj 1" which it will use to spawn scene's -obj 1 which is on a different layer. Using said string rather than creating an actuator on the tile for each object I create.

$\endgroup$
  • $\begingroup$ why don't you 'create' that menu with a few planes ? Make a top menu over which you put several invisible planes that react to the 'mouse over' and are connected to actuators adding new planes that you can eventually click to add your objects. $\endgroup$ – Yvain Nov 17 '16 at 22:32
  • $\begingroup$ If I can do it through python that would be better. Get the object being toggled, set a global string of said object accessible by other objects/scripts and use that string to spawn an object when clicking on the other object. This method would be much more scale-able for adding more and more objects overtime. $\endgroup$ – Drew Nov 18 '16 at 1:12
  • $\begingroup$ Then you still need a "clikable" mesh to pop up the menu. If you want python script instead of using controllers for some tasks that's up to you. First you need a controler for your mouse, and your script will do the rest (let's say parse the categories menu choice; pop up the corresponding sub-menu, and finaly send the choice to the function for adding an object). $\endgroup$ – Yvain Nov 18 '16 at 1:57
  • $\begingroup$ These are at least two questions. Please post the second question "spawn on mouse click" in a second thread. $\endgroup$ – Monster Nov 18 '16 at 6:32
  • $\begingroup$ I understand what your saying @monster, but the two questions are kind of intertwined. I'll elaborate by editing the question again. $\endgroup$ – Drew Nov 18 '16 at 19:02
1
$\begingroup$

Messages

This is a logic brick only solution. It should be sufficient at the situation you described.

Selection handling

In this sample we let selectable object store the selection status in a property called "selected".

When it is "True" the object is selected.

When it is "False" the object is not selected.

Give all selectable objects the property "selected" as boolean enter image description here

Deselect all

When clicking anywhere send a message "deselect".

Any selectable object listens to a message "deselect" and deselects itself on receipt.

enter image description here

You need a (single) managing object that triggers this deselection.

enter image description here

With that you ensure on any right click all objects are deselected.

Select one

The one object the mouse cursor is over will be selected.

enter image description here

You see the selection will take place on the object under the cursor only. All other object will still receive the "select" message but ignore them.

Now let's make your managing object send the "select" messages: enter image description here

It looks pretty much the same as the "deselect" logic. This is as both are triggered by the same key.

What will happen?

One left click:

  • message "deselect" will be send to all objects with message sensor listening to "deselect"
  • message "select" will be send to all objects with message sensor listening to "select"

[all selectable objects receive two messages!]

  • All selectable objects willreceive "deselect" and set property "selected" to False
  • All selectable objects will receive "select"
    • the one with the cursor over it will set property "selected" from (previously set) "False" to "True"
    • all others do nothing and keep "selected" with "False"

This way you can be sure only one can be selected as only one can have the mouse cursor above it.

$\endgroup$
  • $\begingroup$ This looks like it will work for the toggle select, cannot confirm it as I am not at my PC at the moment. $\endgroup$ – Drew Nov 18 '16 at 19:03

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.