thepgi / bge-logic-nodes-add-on

add-on for the blender game engine (2.7) to create node-based logic
8 stars 5 forks source link

PROPOSAL : Keyboard Node The Key pressed And Key value.. #5

Closed vuniverse closed 7 years ago

vuniverse commented 7 years ago

Hello Pgi I have proposal . When i work on a scene i was trying to write text on screen . When someone needs to do this he should set up whole keyboard set and check them to grab the text written. And it will gonna be lots of nodes ; at least around 30

Just this solution flashed .. This Node may have two exit node

If Pressed Key ( a b c d e 1 2 etc)

This way with only one node it may be possible to read what user writes. also can shorten the controls thing.. Only problem is how it can be possible to detect key combinations . Like UP_ARROW&DOWNARROW or SHIFT&A And how to read them for further nodes.

What do you think ?

thepgi commented 7 years ago

I have in the todo list a "key logger" node that should pack the logic needed, for example, in text fields. I haven't thought about it lately but it could work like you describe. An input condition that enables or disables it, one output for the key code, one output for modifier code and one output for the typed character as a string. So if the user presses shift+a you get the keycode for the a button, the keycode for the shift button and the string "A". Then you can use a mathop "add" to concatenate that string to an existing string-property and have the text. I'll try to make it for the next update.

vuniverse commented 7 years ago

That will be awesome.

vuniverse commented 7 years ago

Hello pgi .. I tried the commands.. I went back the file i worked on. :) it works very nice .! There is only one thing. Reported keys are based on EN keyboard layout. Is there a way to change INPUT keyboard layout of the game to other languages ?

thepgi commented 7 years ago

Unfortunately not that I know of. The input library of bge, at least the part that is exposed through python and we can use, kinda sucks. A lot. A tsunami of suck-ness.

vuniverse commented 7 years ago

LOL.. Yes and undocumented/not good documented but amazing software. Just like it came from outer space. And we are to solve the mystery. yes sucks..:D

vuniverse commented 7 years ago

Hello Pgi .. Do you plan to add an MultiDimensional Array Node Set..? I was going to add it as a Proposal but i thought you already might have been planning for it .. Or is it possible to create one with current nodes ?

Example : Array Nest[]

Nest [1] [1] [object] [cube] Nest [1] [1] [occupied] [TRUE] Nest [1] [1] [color] [RED] Nest [1] [3] [object] [NONE] Nest [1] [3] [occupied] [] Nest [1] [3] [color] [] Nest [Active] [FALSE]

Or Array MyData

MyData [nested] [TRUE] MyData [nest_location] [2,2,2]

So each object may have their own data collection that may be used for further processes.

thepgi commented 7 years ago

I miss the reason why one would do that. You can use numbers as property identifiers if you like, so you would write "1,1" in the name field of a get-property parameter or set property action.

vuniverse commented 7 years ago

Yes... but in this case you should find the names of each object you wanna Check. With an array you can collect all object properties in one RECORD object . Example : You have a City and you are building it . Each grid location has a value Occupied TRUE or FALSE. Or value dimension like 3,4 Unit. So how to get precisely if one location is occupied or not. and size ? If i were doing it ..I would open a city record array. And would record each location with the building I put there. At first it will have a location record Occupied=False and Dimension = 3,4 So in case i wanna place a building in an occupied location it will not place before checking if that location was occupied or not. And if the size fits or not. Am i thinking wrong ?

vuniverse commented 7 years ago

Maybe i can use ray Pick. But there will be cases like "puzzle" to check a series of locations to understand if the new piece will fit in that location or not .. Example if i Create a scrabble game. It can not be solved the problem with only ray Pick I guess.

thepgi commented 7 years ago

Basically anything that requires you to explicitly traverse some data structure is out of the scope of the addon. That kind of operations requires a state flow chart which is perfectly possible to represent with blender nodes but it is not compatible with the parameter-condition-action model, because it will introduce operations, like loops, that are won't work. The fall-back for those situations it the Python Module node, that delegates its logic to a python function that the user can define in some custom python module.

vuniverse commented 7 years ago

I guess i understand . I should learn some python then. Thank you .

thepgi commented 7 years ago

Try to find a way to represent your idea as properties of existing 3d objects, in my experience bge reacts better to that. Not that learning or getting a better understand of a programming language (or really anything) is bad idea, that's always good, but it might not be the fastest solution. For example, any grid can be represented with a "real" grid of (possibly hidden) planes for 2d, cubes for 3d so instead of having a data structure to traverse you have direct access to the entries. Things like that.

vuniverse commented 7 years ago

I did not see this message .. Sorry for replying so late pgi... yes i arrive "there" :)) ..Creating invisible objects with properties recorded in them to define the zones . I am working on a practice project like that.

Today i try to make a pendulum.. And I faced a problem. Pendulum rope force needs Trigonometric functions And square root to be calculated. The force formula of pendulum has trigonometric values. Then i will calculate the x y x parameters of this for to apply it. Do you plan to add a math node like blender have in cycles.?

thepgi commented 7 years ago

I can add math operations, no problem but be prepared, it will be slow as in "unusable slow". Cycles has the advantage that the nodes are backed up by native code while an add-on like this is constrained to use python which, oddly enough, can chew lots of math by using a library like numpy but not few math, like a single physical computation. Performance-wise, a better solution in your case would be to use the physics system. I have no idea how, but you can create a pendulum (maybe with some kind of constraint). If you have any suggestion for the math functions to be added, this is what comes to my mind right now:

pow A^B pow 2 pow 3 square root cubic root cos, sin, tan, atan, children and parents... log a PI constant

vuniverse commented 7 years ago

Maybe : Absolute, Floor and Ceiling can be useful too. Always multiplying a value with -1 to get absolute lol. Oh and constraints i should work on them . I know how to use in normal blender simulations but when it comes to GAME engine. I am new on that..

vuniverse commented 7 years ago

But sometimes it is necessary to interrupt the normal physic engine and add your own methods. Example ..I tried to add a space ship / aircraft behavior to a xwing fighter. Well ( laughs).....it is simple.. Sure not very advanced .. Only some forces to get spaceship in to equilibrium. And there is no vehicle behavior in bullet ..At least only i know is a car. And no mores.. So flexibility is nice and useful and also to have more instruments to do what you dream.

thepgi commented 7 years ago

Ok, the plan is to have a node that takes up to four parameters and let you write the function that produces the output. So the user writes the string:

3_a_b*cos(c)

connects or provides (as fields) the values for a, b and c and the node will spit out the result as its output. The node also provides predefined functions as selectable entries, so if you one wants to compute a^b it selects "pow(a,b)" instead of... writing "pow(a,b)". We like lazy users :D. I'll report the results...

vuniverse commented 7 years ago

Excellent lol.. That is more flexible and better ! Btw I will send the spaceship file when i fix a minor sound problem . Lazy users send salutes :D

vuniverse commented 7 years ago

Hello Pgi .. I have a set up like this. This logic connected to a object rezzer creates random spaceships in a random time interval... ADD OBJECT Node has object name output. But when i rez the object instantly i wanna locate it. SET GAME OBJECT MEMBER needs a condition. But if i connect that condition of Time filter to SET GAME OBJECT MEMBER as well as ADD OBJECT, It can create before/after conflict. Cause The object positioning and OBJECT REZZER will get the pulse in same moment. How to solve this problem ? If ADD OBJECT node has an Object Added output along side the ADDED OBJECT node, it will not create interval problems.. 2016-09-04 19_09_37-blender_ c__users_marianne64_desktop_blender works_blender logic nodes_projects

vuniverse commented 7 years ago

Maybe should be like this .. for continuously changing time interval . 2016-09-04 19_21_12-blender_ c__users_marianne64_desktop_blender works_blender logic nodes_projects

thepgi commented 7 years ago

That setup is perfectly possible. While the whole network is evaluated in a single step, nodes in the network are ordered by dependencies. In your case, the tree code builder will detect that the Set GameObject Member node depends on the Always condition output AND on the Add Object output, so it will postpone the evaluation of the Set GameObject Member node after both the Always and the Add Object have been evaluated.

vuniverse commented 7 years ago

Hi Pgi.. It worked :)) This is the file i work on. It is just a 2d spaceship control anyway. But lots of practice possible with this. Where i was lost : I wanna destroy a created object---> by itself. So here on this file : https://ufile.io/7cf31 SHIP rezzes a bomb,BOMB gives itself a velocity.When BOMB collides wih something : It Creates a Bomb particle and kills himself.

What i was aiming : particle should also destroy itself in a second. But Time barrier some how did not work for this object and particle survives. :D Question i could not answer is : "Are the Logic blocks of the objects in hidden layers starts with game or on the moment they were created ? " Then Time barrier should work. But it did not the way i made it.

Controls for this stage : R (Run Engine) : U (Stop Engine) UP_ARROW Forward / LEFT & RIGHT ARROW Mouse Click : FIRE

thepgi commented 7 years ago

I'll check out the file. Every time I look at the Time Barrier node I wonder "what the heck does this really do?" And I wrote it!

I forgot, to answer your question: logic attached to an object in a hidden layer should start execution when the object is added and stops execution when the object is removed. So if the ship object gets removed also the logic it contains is removed. If the particle life is controlled by the logic of the ship then when the ship is removed the particle will have no logic.

vuniverse commented 7 years ago

OK then ,the ALWAYS pulse once -->> starts with the object addition. Then time barrier triggered with it so should remove itself in 5 seconds.. This time barrier with collision trigger works fine. But with "always" did not.. In "Ship sound" i used the time barrier. : There are 3 sounds. one is launch.. then second sound is a loop .. I added a 9 second time barrier. So first sound starts and after 9 nine seconds sound : loop starts ... Seems like working there :D
( Sometimes KEY Pressedand Mouse Data not detected by engine : You can see it when you use R key to launch the ship .And mouse clicks for bomb .. I dont know why... = | * )

thepgi commented 7 years ago

Your setup looks ok - save for an unconnected vector node that spits out an exception during the execution because it has no input. A kind of minor bug I'll fix. In BombParticle, you need a Time Elapsed condition for the Remove Object node. The Time Barrier does something else, actually "if a certain condition stays true for a certain period of time, then do something". Here's the description of (most) nodes.

http://www.tukano.it/applications/bgenetlogic/bgelogicnodes.html

vuniverse commented 7 years ago

yay ! Time elapsed worked ...! Thank you .