Using Bricks scripting

Hi. Please bare with me. I’m still noob and learning how to program.

A question please, how do we script a brick (Ray, random, etc etc) with by just importing it with a script and not using any twirly noodles (Nodes). I want to learn to rely on scripting and only be using Always->Python.

I hope you get my point. lol.

THANKS! :slight_smile:

value = bge.logic.getRandomFloat() = a random float

math module has a ton of stuff for random number generation

for rays

object.rayCast()

for a radar, you can use a collision sensor in a sensor object

for near, you can use list sorted each frame, the closest object gets pushed to the first object on the list, if it’s value is outside a range none are near,

you can itterate up the list that is sorted, and grab all inside a range, and stop proccessing a list with break command.

I will try and post some examples tonight if I can stay awake a bit after work is over in like 40 minutes.

use Panda3d :wink:

I get why you think like that. The point is, you want to use the BGE in a different way as it is designed. The SCA (Sensor-Controller-Actuator) is the build-in event system. There is no other.

You can bypass this system (as you suggested) but you will not find build-in support for it. You need to manually create the complete framework. Luckily you are not the first with that ideas. Therefore I suggest to search the resource sub-forum (I cant tell what to look for, sorry).

If you want to create logic bricks via scripts you are within the Blender scripting (rather than BGE scripting). I suggest to check the Python support subforum.

yeah, the logic bricks really do make your life easier, and should be used to save cpu time WHENEVER possible.

using states + sensors running small modules is the way to go to get good performance

like

when timer is not zero-----------(python that does stuff and reduces timer)

so effects can run only when you need it,
another option, is adding objects to a scene that then run code against targets, over time and the end thenselves,

basically

always-------python god script

is a bad idea

unless its

always-----manage feature that has to run every frame

like Physics LOD or a dynamoc lighting manager, or???

the problem is that there are NOT prefiltred list(not exposed)
i had already suggested to expose a list of actors (scene.objects,scene.cameras,scene.lights,scene.actors…)

keeping in count that the actor are more or less 5% of all objects.
iterate scene.objects is really wasting.
iterate scene.actors NOT.
starting from there is trivial simple create a set of sensors:
near
radar
near visible
radar visible

these can be simple function that return a list of objects when called

ex-> near_enemies = obj.near_hits(distance=20.0, prpp=“enemy”) #return a list of objs

this is doable only if you do a custom list of “actors”
register it in a custom list
then a looper validate the list each frame.

marcoIT

if you have many many items to sort through that are static, non actors, (like walls for instance you are doing some FX to)

check out a array, or a kdtree or a bvhtree, you can get the closest items in a kdtree for little cost after building and balancing it,