if I use a lot of sensors with pulse mode running all the time, am I going to use up too many resources?(what I’m using the pulses for)
[INDENT=2]
Answer to 2 made this question irrelevant.
[/INDENT]
[INDENT=2]
[/INDENT]
2. are “if” statements the proper way to change the color of something when I mouse over it?
import bge #use every time
import mathutils
cont = bge.logic.getCurrentController() #use every time
own = cont.owner #use every time
mouseover = cont.sensors["mouse over"]
if mouseover.positive:
cont.owner.color = [1,1,1,0]
else:
cont.owner.color = [0,1,0,0]
[/TABLE]
where do I enter/attach python scripts that I want to run every time I start my game?
Answer: the camera is a good object to attach all your python scripts that you want to run when your game starts up
if not mouseover.positive:
print ("false")
cont.owner.color = [1,1,1,0]
else: ## triggered
print ("true")
cont.owner.color = [1,255,1,0]
I would set your mouse sensor to tap also…just check the console to see how many times its triggering to see how you need to set things up. You could probably even do something like this To make it only execute if the colors not changed already
if not mouseover.positive:
print ("false")
if not cont.owner.color == [1,1,1,0]:
cont.owner.color = [1,1,1,0]
else: ## triggered
print ("true")
if not cont.owner.color == [1,255,1,0]:
cont.owner.color = [1,255,1,0]
EDIT: After trying the code I notice that you should not use tap the way I have the code wrote. But the latter code does work
Object.color RGBA values are entered ranging from 0.0 to 1.0 so I don’t see how any of those scripts would work. The last number is alpha which needs to be other than 0.0 if you want your object to be visible at all.
I tried using the “positive” attribute originally, but I must have done something wrong. using “positive” fixed my problem altogether. thank you
On adding a object (e.g. at scene start)
Always [no pulse] -> Python controller
On every single frame (as long as the object exist):
Always [true pulse] -> Python controller
I meant, where do I attach the python code too. I read somewhere that using the camera for all your “always” python stuff was a good idea. I figured there would be a special place in the BGE that I would assign the python script. using the camera should work for what I am doing.
I realized late last night that you use 0-1 not 0-255. I’m glad that if I had not figured that out, your post would have corrected my mistake. thank you.
The camera is a really worse place. It is a camera and should do camera things only.
In doubt create a new empty. Give it a meaningful name that you know what it is doing. In your case it seems you change the color when the mouse cursor is over an object. I suggest to call it: “ColorChangeHover”.
As it does not have a mesh it will not eat rendertime.
This way you can easily move this logic around as one piece. You can even share it with other files. You can enable, disable the logic just by moving the object to an hidden layer and back (or by switching layers). You can even have multiple different implementations.
HINT: when you move the mouse from one object to another without hover over background, you will see the controller gets not triggered. You can enable this with KX_MouseFocusSensor.usePulseFocus. Unfortunately there is no switch in the GUI. So you need Python to enable this configuration.