jpEventQueue is required by several of my plugins and most of the time, you only need to reference jpEventQueue in your ShiVa project and your are done.
However, you can use it with your own plugins or native code, to send events from your xCode or Android project to the ShiVa project.
This tutorial will learn you how to use jpEventQueue in your native projects and get rid of all of the hard stuff of handling events yourself.
You should use jpEventQueue for 3 reasons :
Before you can use jpEventQueue in your native project, ensure the jpEventQueue library is referenced in that project.
If you are creating a new xCode or Android project from the Authoring Tool, verify that jpEventQueue is referenced in your ShiVa project before exporting the .stk file for the desired target. This way, the jpEventQueue library will automatically be referenced in the newly created native project.
In case the native project was already created, please refer to the following tutorial to learn how to add the plugin to your project :
Referencing a new Plugin in an Existing Native Project (iOS / Mac / Android)
iOS |
---|
Additionally for iOS only, you must download the Additional Files provided with jpEventQueue. It contains several header files (.h) you will use to be able to call functions that are inside the jpEventQueue static library. Refence them in your xCode project by drag and droping their parent folder in the Project Navigator of xCode and choose "Copy items if needed". |
Import jpEventQueue from the file where you want to use it
iOS | Android |
---|---|
#import "jpEventQueue.h" | import com.jpierron.jpeventqueue.jpEventQueue; |
iOS | Android |
---|---|
[jpEventQueue push:@"MyAIModel" andEvent:@"onMyHandler"]; | jpEventQueue.push("MyAIModel", onMyHandler"); |
iOS | Android |
---|---|
[jpEventQueue push:@"onMyHandler"]; | jpEventQueue.push("onMyHandler"); |
You can add parameters by adding up to 10 arguments to the previous functions :
iOS |
---|
[jpEventQueue push:@"onMyHandler" p0:@"First param value" p1:"Second param value"]; [jpEventQueue push:@"MyAIModel" andEvent:@"onMyHandler" p0:@"First param value" p1:"Second param value"]; |
Android |
---|
jpEventQueue.push("onMyHandler", new jpAIVariableWrapper("First param value"), new jpAIVariableWrapper("Second param value")); jpEventQueue.push("MyAIModel", onMyHandler", new jpAIVariableWrapper("First param value"), new jpAIVariableWrapper("Second param value")); |
In the above examples, you've seen how to send string parameters, but jpEventQueue handles several other types (string, boolean, number and nil value)
Expected in ShiVa | Objective-C class | Examples | Note |
---|---|---|---|
nil | nil | - nil | |
string | NSString |
| |
number | NSNumber |
| |
boolean | jpBoolWrapper |
| Add the following statement at the beginning of the file : #import "jpBooleanWrapper.h" |
Expected in ShiVa | Java class | Examples |
---|---|---|
nil | null | - null |
string | jpAIVariableWrapper ( String ) | - new jpAIVariableWrapper("Message from Java") |
number | jpAIVariableWrapper ( float ) | - new jpAIVariableWrapper(5) - new jpAIVariableWrapper(5.0f) |
boolean | jpAIVariableWrapper ( boolean ) | - new jpAIVariableWrapper(true) - new jpAIVariableWrapper(false) |