# How call UFUNCTION (BlueprintImplementableEvent) from JS with EMSCRIPTEN and error: Module.ccall is not function?

**URL:** <https://forums.unrealengine.com/t/how-call-ufunction-blueprintimplementableevent-from-js-with-emscripten-and-error-module-ccall-is-not-function/758421>\
**Category:** C++\
**Tags:** webgl, HTML5, unreal-engine, CPP, question\
**Created:** [January 28, 2023, 3:36am UTC](https://forums.unrealengine.com/t/how-call-ufunction-blueprintimplementableevent-from-js-with-emscripten-and-error-module-ccall-is-not-function/758421 "2023-01-28T03:36:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ananasdas181](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ananasdas181/32/616271_2.png) [@ananasdas181](https://forums.unrealengine.com/u/ananasdas181)\
**Post date:** [January 28, 2023, 3:36am UTC](https://forums.unrealengine.com/t/how-call-ufunction-blueprintimplementableevent-from-js-with-emscripten-and-error-module-ccall-is-not-function/758421/1 "2023-01-28T03:36:03Z")

</div>

I am making a game for HTML5. At a certain moment I call the ad block, before that I put the game on pause. When the player closes the ad block, I need to unpause the game (I use Blueprints). I need to call UFUNCTION (BlueprintImplemetableEvent) from JS, but I didn’t find how.

I use this code in cpp:

```auto
#ifdef __EMSCRIPTEN__ 
#include "SDL/SDL.h"
#include "emscripten/emscripten.h"
#include "emscripten/html5.h"
#else
#define EMSCRIPTEN_KEEPALIVE
#endif 

#include "string"
#include "iostream"
#include "sstream"

//'"FString Text" I assign to test in Blueprints

void AChristmasMole4_23CPPGameModeBase::Test()
{

	

	std::string OutboundSendString(TCHAR_TO_UTF8(*Text));

#ifdef __EMSCRIPTEN__ 
	EM_ASM_ARGS({
		var theText = UTF8ToString($0);

		console.log('Hello' + theText);
		}
		
		, OutboundSendString.c_str()
		);
	
	emscripten_run_script("testJS();");

#endif
}

extern "C" void EMSCRIPTEN_KEEPALIVE CallTest(char *str)
	{
	
//I don't know how to call UFUNCTION(BlueprintImplementableEvent) here
//I used (char *str) because I don't know how to use Module.ccall to call a function with no arguments

	}

```

In [ProjectName] -Shipping.UE4.js file:

```auto
function testJS()
 {
    var str = "Hi from JS!";
    var lenUTF8 = Module.lengthBytesUTF8(str) + 1;
    var ptr = Module._malloc(lenUTF8);
    Module.stringToUTF8(str, ptr, lenUTF8);
    Module.ccall('CallTest', 'null', ['string'], [str]);
    Module._free(ptr);
}

```

When I call the testJS() function, it shows that Module.lengthBytesUTF8 is not a function and Module.ccall too.

 ![ScreenError](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/5/16562c4d0a04cbed265e6534d2bcf1fbe89ae134.jpeg)

I’ve looked at a lot of threads on this topic but couldn’t find an answer to my question.

And my code knowledge is very noob.

---

<div class="post-metadata">

**Author:** ![ananasdas181](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ananasdas181/32/616271_2.png) [@ananasdas181](https://forums.unrealengine.com/u/ananasdas181)\
**Post date:** [February 1, 2023, 3:40pm UTC](https://forums.unrealengine.com/t/how-call-ufunction-blueprintimplementableevent-from-js-with-emscripten-and-error-module-ccall-is-not-function/758421/2 "2023-02-01T15:40:17Z")

</div>

I DID IT!!!

I didn’t call Module.ccall, but I was able to do without it.  
I created an integer in an HTML file and placed it in the “HEAD”

```auto
<script>
        var numTest = 0;
    </script>

```

When the player presses the START button, the testJS() function is called.

in cpp:

```auto
#ifdef __EMSCRIPTEN__ 
	emscripten_run_script("testJS()");
#endif

```

in HTML:

```auto
<script>
function testJS(){
numTest = 1;
}
</script>

```

Each tick checks to see if numTest has changed to 1.  
If numTest=1 then EventUnpause is activated and numTest returns to 0.

in cpp:

```auto
#ifdef __EMSCRIPTEN__ 
	int CallUnpause = EM_ASM_INT({
		return numTest;
		});

#else
	int CallUnpause = 0;
#endif

	if (CallUnpause >= 1)
	{
		Unpause();

#ifdef __EMSCRIPTEN__ 
		emscripten_run_script("numTest = 0");
#endif
	};

```

---

<div class="post-metadata">

**Author:** ![RaybulEgor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RaybulEgor](https://forums.unrealengine.com/u/RaybulEgor)\
**Post date:** [September 27, 2024, 1:08am UTC](https://forums.unrealengine.com/t/how-call-ufunction-blueprintimplementableevent-from-js-with-emscripten-and-error-module-ccall-is-not-function/758421/3 "2024-09-27T01:08:58Z")

</div>

I don’t really like working with global variables, I would like to have a callback in JavaScript that would trigger events in the drawings, I do it like this

.h

```auto
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
	GENERATED_BODY()

public:
	AMyActor();

protected:
	virtual void BeginPlay() override;

public:
	virtual void Tick(float DeltaTime) override;

	UFUNCTION(BlueprintImplementableEvent)
	void SetLocation(int32 Value);
};

static int32 Location;

```

.cpp

```auto
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif

#include "MyActor.h"
#define EXTERN extern "C"

AMyActor::AMyActor()
{
	PrimaryActorTick.bCanEverTick = true;
}

void AMyActor::BeginPlay() { Super::BeginPlay(); }

void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (Location)
	{
		SetLocation(Location);
		Location = 0;
	}
}

#ifdef __EMSCRIPTEN__
EXTERN	EMSCRIPTEN_KEEPALIVE
#endif
void SetLocation(int32 value) { Location = value; };

```

.ts

```auto
const engineApi = {
    setLocation(value: number) {
        Module['_SetLocation'](value);
    },
};

export default engineApi;

```

then i can import this api into any file and call an event

---

<div class="post-metadata">

**Author:** ![alphabrox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alphabrox](https://forums.unrealengine.com/u/alphabrox)\
**Post date:** [December 9, 2024, 12:52pm UTC](https://forums.unrealengine.com/t/how-call-ufunction-blueprintimplementableevent-from-js-with-emscripten-and-error-module-ccall-is-not-function/758421/4 "2024-12-09T12:52:42Z")

</div>

To work Module.ccall you need to export ccall function (add it to exported methods array) in Engine\Platforms\HTML5\Source\Programs\UnrealBuildTool\HTML5ToolChain.cs (~473 line):

`Result += " -s EXPORTED_RUNTIME_METHODS=\"['stringToAscii', 'ccall']\"";`
