Second Version
It seems to work. Looks better now.
Line Draw
I guess there is some mixed coordinate on the line calculation. (I will have a look later at that topic).
Default value
Hint: You can give a property a default value when reading. So in listen.py you can replace
prefix = ""
if 'prefix' in own:
prefix = own['prefix']
with
prefix = own.get('prefix', "")
Hiding values
(listen.py)
You successfully retrieve the body from the message. Unfortunately you still set the text if there is none. This clears out the text you set before.
This is pretty simple to solve.
Replace
if incoming.positive:
body = incoming.bodies[0]
own.text = prefix+body+suffix
with
[if incoming.positive:
body = incoming.bodies[0]
own.text = prefix+body+suffix # --> just moved into the sensor.positive block
This is the reason why most of my BGE callable functions start with “if not allSensorsPositive(): return”
[edit]
Printing class instances
The default printing only tells you what class the object is and what internal id is has. So not really something useful.
But your both classes Cube and Hex have some more interesting information: the coordinates
For easier printing of your classes to the console I strongly suggest to override the default output.
Example:
class Hex:
# better use doc strings to describe your class
"""A generic Hex object w/ axial coordinates"""
...
def __repr__(self):
return "Hex({},{})".format(
self.p, self.q)
class Cube:
"""A generic Cube object w/ cubic coordinates"""
...
def __repr__(self):
return "Cube({},{},{})".format(
self.x, self.y, self.z)
a cube would look like this:
Cube(3,-6,3)
Efficiency
As I wrote earlier the constantly running code is really disturbing when debugging. When adding print statements the console is flooded with output. As this is not necessary I strongly suggest to review your sensor settings.
Brush
Always with [True Level Trigger]. There is no need to run the “goGo” all the time. Run it once to create the grid and that is all -> rename it to “on creation”, switch off [True Level Trigger].
Message incoming - is fine. But here I would enable [True Level Trigger] as consecutive messages needs to be processed too. Btw. What is this message telling?
Mouse MouseOver. Activate [Pulse] that it updates when the mouse over detects a different HEX. I suggest to name the sensor “over HEX” - reads -> Mouse over Hex
Mouse MouseClick. Why tap? that is useless here … deactivate it. The controller gets triggered when you press or release the button. I’m sure you only need the “just pressed” event. I suggest to call this sensor “set area” to express this event sets the area.
With this changes (mainly the change at the Always) it is possible to produce better output in your console. As positive side effect, it runs much faster.
Example output (printing the results of cube_line):
Blender Game Engine Started
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[Cube(3,-6,3)]
[Cube(3,-6,3)]
[Cube(3,-6,3)]
[Cube(3,-5,2)]
[Cube(3,-5,2)]
[Cube(3,-5,2)]
[Cube(4,-6,2), Cube(3,-6,3)]
[Cube(4,-6,2), Cube(3,-6,3)]
[Cube(4,-6,2), Cube(3,-6,3)]
[Cube(4,-6,2), Cube(3,-6,3)]
[Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(5,-6,1), Cube(4,-6,2), Cube(3,-6,3)]
[Cube(6,-7,1), Cube(5,-7,2), Cube(4,-7,3), Cube(3,-6,3)]
[Cube(6,-7,1), Cube(5,-7,2), Cube(4,-7,3), Cube(3,-6,3)]
there are still repetitions, but much better than before.