ShiVa3D
keyboard handler
All about the StoneScriptkeyboard handler
by jdebroy » 17 Aug 2012, 03:55
Hi,
Is there a way of using a keyboard handler (like onKeyboardKeyUp) without placing it on the Users main AIs?
Let me explain a little more. To capture keystrokes or other input I have to create the handler on the User's main AIs and send events to the tagged or runtime created objects on my scene.
If I place an onKeyboardKeyUp handler on the Object's AImodel (a one not included on the User's Main AIs), there is no response. It would be great and simpler flow if I can just capture keystrokes directly on any AImodel.
In any case, the editor allows to include those handlers on object's AI, but there is no alert that the object's AI does not respond to user input, so it is confusing. Should it respond to keystrokes/user input or not?
Is there a way of using a keyboard handler (like onKeyboardKeyUp) without placing it on the Users main AIs?
Let me explain a little more. To capture keystrokes or other input I have to create the handler on the User's main AIs and send events to the tagged or runtime created objects on my scene.
If I place an onKeyboardKeyUp handler on the Object's AImodel (a one not included on the User's Main AIs), there is no response. It would be great and simpler flow if I can just capture keystrokes directly on any AImodel.
In any case, the editor allows to include those handlers on object's AI, but there is no alert that the object's AI does not respond to user input, so it is confusing. Should it respond to keystrokes/user input or not?
- jdebroy
- Expert Boarder

- Posts: 126
Re: keyboard handler
by Selzier » 17 Aug 2012, 04:14
The FPS Demo does this by using this code in the "InputCore" AI which IS included in the User Main AI. But sends the keyboard event off to the AICamera which IS NOT a part of the user main AI >
- Code: Select all
--Forward to camera
local hScene = application.getCurrentUserScene ( )
local hCam = scene.getTaggedObject ( hScene, "Camera" )
if ( hCam )
then
object.sendEvent ( hCam, "AICamera", "onKeyboardKeyDown", kKeyCode )
end
- Selzier
- Platinum Boarder

- Posts: 344
- Location: Boise
Re: keyboard handler
by error454 » 19 Aug 2012, 00:22
This can be confusing at first but it makes much more sense once you understand the difference between User AI and Object AI.
User AI is AI associated with a user. Only users can type on a keyboard, move a mouse and use a joystick. This is why User AIs are the only AIs that receive those handler calls.
You can technically make any AI a user AI but it doesn't make sense to. For instance, an explosion AI that draws explosion animations. This AI doesn't require keyboard input and isn't tied to a single user.
You can simply forward events as posted above. But don't feel like you have to forward at the lowest level. For instance, instead of sending onKeyboardKeyUp to your object, you could send onMoveUp or onAccelerate if it makes your code/events easier.
User AI is AI associated with a user. Only users can type on a keyboard, move a mouse and use a joystick. This is why User AIs are the only AIs that receive those handler calls.
You can technically make any AI a user AI but it doesn't make sense to. For instance, an explosion AI that draws explosion animations. This AI doesn't require keyboard input and isn't tied to a single user.
You can simply forward events as posted above. But don't feel like you have to forward at the lowest level. For instance, instead of sending onKeyboardKeyUp to your object, you could send onMoveUp or onAccelerate if it makes your code/events easier.
Re: keyboard handler
by remiaboudib1 » 07 Nov 2012, 21:23
hello,
i'm trying to solve a similar problem i created a AI for an object and i place some code for on keyboard key down, and i created another AI for a second object and also he has some code in his onkeyboardkeydown....the problem is when i send event for both of them from the main AI it all mess up the send event goes for only one AI where is the problem???please help me
i'm trying to solve a similar problem i created a AI for an object and i place some code for on keyboard key down, and i created another AI for a second object and also he has some code in his onkeyboardkeydown....the problem is when i send event for both of them from the main AI it all mess up the send event goes for only one AI where is the problem???please help me
- remiaboudib1
- Fresh Boarder

- Posts: 17
Re: keyboard handler
by MrGamer » 07 Nov 2012, 21:52
Try to use this code in user ai
it will send key down to every object in scene and you can handle input there.
- Code: Select all
local hScene = application.getCurrentUserScene ( )
if ( hScene~=nil )
then
scene.sendEventToAllObjects (hScene , "*","onKeyboardKeyDown" ,kKeyCode )
end
it will send key down to every object in scene and you can handle input there.
Play game win cash prize
http://moneybackapps.com/
https://play.google.com/store/apps/developer?id=Money+Back+Apps
http://moneybackapps.com/
https://play.google.com/store/apps/developer?id=Money+Back+Apps
6 posts
• Page 1 of 1