Yooooooo!!! I am so happy! I just made my first fully working script, it’s extremely basic and even a child could understand that, but I am happy with what I made!
So, this script can be used to change r, g, b, and alpha values of the script, its very simple, here, have a look at it
from bge import logic
C = logic.getCurrentController()
O = C.owner
red = C.sensors['red']
green = C.sensors['green']
blue = C.sensors['blue']
alpha = C.sensors['alpha']
red1 = C.sensors['red1']
green1 = C.sensors['green1']
blue1 = C.sensors['blue1']
alpha1 = C.sensors['alpha1']
if red.positive:
O['red'] += 0.1
if green.positive:
O['green'] += 0.1
if blue.positive:
O['blue'] += 0.1
if alpha.positive:
O['alpha'] += 0.1
if red1.positive:
O['red'] -= 0.1
if green1.positive:
O['green'] -= 0.1
if blue1.positive:
O['blue'] -= 0.1
if alpha1.positive:
O['alpha'] -= 0.1
if O['red'] > 2:
O['red'] = 2
if O['green'] > 2:
O['green'] = 2
if O['blue'] > 2:
O['blue'] = 2
if O['alpha'] > 2:
O['alpha'] = 2
if O['red'] < 0:
O['red'] = 0
if O['green'] < 0:
O['green'] = 0
if O['blue'] < 0:
O['blue'] = 0
if O['alpha'] < 0:
O['alpha'] = 0
r = O['red']
g = O['green']
b = O['blue']
a = O['alpha']
O.color = [r,g,b,a]
Yeah yeah I know that I could have used a keyboard module or something instead of these many sensors, but I like this method. And I would like to thank my friend, blender games 3d for helping me to learn everything I know now! And thank you all guys for your support!
I was just showing him that an assignement can be done in 1 line even if there’s some more additionnal conditions.
You have already 4 " if" and 1 loop for this particular simple case. If Ansh wants to tune his values red (0-2) but blue (3-5) and call “green1” green2 … +0.2 instead of 0.1 then you good to add another load of “if” to deal with all the new particular cases and the loop on properties ( a good one) won’t work anymore
please, i respect your work very much and you have probably more knowledge that I in Python, but don’t be like those people trying to show “they know best” it’s very irritating. (i didn’t use single letter variables)
And now you got 1 if statement/check. So depending if all keys can be pressed and used at the same time, you can lower the workload for those statements.
If you press up, normally you won’t press down, so adding an el(short for else) works wonders because it does not need to check the down key while up is pressed. (same for the orhet keys/functions).
2 letters (if not a word) is also not good, what does DN mean? yeah down, but dn does not explicit say that it means down, maybe it means dual numbers, or whatever…
Nice to show someone how it can be, but this is just a complete mess, faster yes, but for a scripter (in a team) this would be the biggest nightmare.