Welcome, Guest

Author Topic: Js to flowGraph  (Read 2772 times)

Deltax

  • Posts: 5
    • View Profile
Js to flowGraph
« on: November 17, 2014, 06:27:07 AM »
Hi,

I'm trying to send an event/call in js to use UI:Functions:Game:ExitGame.
I tried to use CoherentUI_Plugin:HandleEvent and engine.trigger but that doesn't work.

Any idea ?

Hristo

  • Administrator
  • *****
  • Posts: 577
    • View Profile
Re: Js to flowGraph
« Reply #1 on: November 18, 2014, 05:21:31 AM »
Hi Deltax,

Using the HandleEvent event on the game engine side is the correct way to do this. Note however that in its current implementation it only supports string or bool arguments. If you need other types you need to add similar implementations in the C++ code.

On the HTML/JS side you just need to make sure that you include the coherent.js file and then use the engine.trigger to trigger event in the game.

Deltax

  • Posts: 5
    • View Profile
Re: Js to flowGraph
« Reply #2 on: November 18, 2014, 06:32:36 AM »
I want to quit the game.
I tried this :



Code: [Select]

<li onClick="javascript: quit();"><div class="last"><p>Quit</p></div></li>
<script src="js/coherent.js"></script>
<script type="text/javascript">

function quit() {
engine.trigger('onExit', 'exit');
}

</script>

But it doesn't work.
Maybe you will see what I'm doing wrong

Nick

  • Administrator
  • *****
  • Posts: 475
    • View Profile
Re: Js to flowGraph
« Reply #3 on: November 21, 2014, 07:07:04 AM »
In the flowgraph that you're using you're referencing the second parameter of the engine.trigger call, but you're supplying only the string param "exit" so the bool will always be false. It should look something like "engine.trigger('onExit', 'exit', 1);". If you want to extend the functionality you can add your own event types in the FlowCUIHandleEvent.cpp source file.

I'm also not really sure that that the "OutputHUD" node will be fully executed when the "HandleEvent" node tries to obtain the View ID - you set up a breakpoint in visual studio to check that.
R&D Director @CoherentLabs

Deltax

  • Posts: 5
    • View Profile
Re: Js to flowGraph
« Reply #4 on: December 12, 2014, 02:03:00 AM »
Hi,

thanks for answer.

I have tried a lot things, register the event in c++, override OnCallback & OnScriptMessage but js trigger never call any c++ function.
So I tried use 2.3 (because it could be a 1.8 error) but CreateViewContext always return NULL.

I don't know what to do.

Hristo

  • Administrator
  • *****
  • Posts: 577
    • View Profile
Re: Js to flowGraph
« Reply #5 on: December 12, 2014, 07:29:23 AM »
Hi Deltax,

How did you implement the handler in C++?

Here's a simple sample:

In your C++ code

first make sure that you include:
#include <Coherent/UI/View.h>
#include <Coherent/UI/Binding/EventHandler.h>
#include <Coherent/UI/Binding/String.h>

then use OnReadyForBindings to register for the myTestEvent

Code: [Select]
static void TestEventHandlerFunc()
{
OutputDebugStringA("Test handler called");
}

void CCoherentViewListener::OnReadyForBindings( int frameId, const wchar_t* path, bool isMainFrame )
{
m_ReadyForBindings = true;
if (isMainFrame){
m_pView->RegisterForEvent("myTestEvent", Coherent::UI::MakeHandler(&TestEventHandlerFunc));
}
}

and in your HTML trigger the myTestEvent with engine.trigger

Code: [Select]
<html>
<head>
    <title>Coherent UI Demo</title>
</head>
<body>
<script src="js/coherent.js"></script>
<script type="text/javascript">
function myTestEvent() {
console.log ('engine myTestEvent triggered');
engine.trigger('myTestEvent');
}
</script>

<button onclick="myTestEvent();">Send myTestEvent</button>

</body>
</html>

Deltax

  • Posts: 5
    • View Profile
Re: Js to flowGraph
« Reply #6 on: December 12, 2014, 08:54:32 AM »
Thanks !

Now I know where is my bad.
I was using the flow node handle (who doesn't work for an unknown reason) and it was never called.
I had tried what you gave me with a coherent bind, maybe that why it didn't work.

I feel really stupid seeing your answer, you saved my day !

Deltax

  • Posts: 5
    • View Profile
Re: Js to flowGraph
« Reply #7 on: December 13, 2014, 01:09:22 AM »
Now I know more about the flownode handle.
It work only when there isn't any argument in the trigger.

Maybe some one know why ?

Tags: