Update Function on HTML functions how is it called?

so i have a template i have built in html
and i added the normal functions to the js file.

most of them work fine.

how ever update does not work as i expect from the official client.
my update function is called when i use play.
if i call update the server says there is not function update.

server 2.3.3 LTS
client 2.2
windows 10

Just to be sure: Your update function has a parameter, right:

function update(data){

well mine reads

function update(msg){


Mine works fine,
just make sure that those functions are available in global namespace - if you open console in your web browser, check that function can be run straight from JS console.
Also here https://www.indr.ch/2019/01/creating-production-ready-html-templates-for-casparcg/ is a nice aticle for begining with interactive html+js templates for caspar, helped me a lot :slight_smile:

so i am back at this.
and i have the same problem.

the most resent build 2.3.3
new computer this time.
the update function gets called only when i play from the client.
not when i call for an update.

when i call update in the client the server says:
[error] html[file://E:/ServerTestMedia/Templates/MTGFX/WEBGFXMT.html] 1280 720 50.000000 Log: Uncaught TypeError: update is not a function.

i can in fact call the update function from the java counsel in my test browser.
it works as it should.

and just for giggles i moved the update function to the top to be the first function to load.

i feel like it is a server issue. as it calls it the first time when i paly it.
but that is the only time i can get it to call the update.

this is my function

function update(msg){
    console.log('update called');

    //remove crap from Casparcg String then make a real Json
    new_msg=msg.replace('\\', '');

    //replce local html with correct text


i just t solved this.

the problem is this.
in my code.

the function was this.


it needs to be

update (msg) {}

i am not sure why that matters.

i all so am not sure which is correct.

The Javascript parser has to recognise many tokens without any white space. Removing white space is one of the actions in a javascript code minimiser/minifier. The following code layouts are both valid:

function update(str){if((str===undefined)||(str===null)) ...}
function update (str) { if ((str === undefined) || (str === null)) ...}

I tend to use the white spaced version for ease of reading, but I have removed the white spacing and run a template on server 2.3.3, client 2.2 and all ran as expected. The key properties for the play, update, stop, next functions is that they are visible at the global level.

I appreciate your reply.
Yes i understand,
Both minimized code and the global name space for functions. I have written a lot of templates for casparCG over the years,
As well as a lot of other projects.

One of the things i like about JS is that it is not white space sensitive.
That is why i do not understand the behaviors i am seeing.

This is the build i have.


The one from 2021-12-01 windows

I see there is a new build from yesterday. I may try that.

For several months I have been using the Github V2.3.3_LTS release that has the image scroller added back into the codebase (here). The server prints “Playout Server 2.3.2 4de6d18f Dev” in the log on startup. Release date was 16th March 2021. I also have checked templates on the latest NRK Github release as the users may have both versions deployed on their site.

A really silly thought, but just in case… When did you last restart the server? Are you suffering one of those problems cleared by a cold reboot? I know this is a very improbable cause, but I have suffered from too many such improbables!

i test on my computer at home so i run a local server here.
i reboot it often.
good idea though.
i to in production have had issues like that.

so this problem started when i updated a server.
i made a template that used a lot of sprite sheets for some custom animations.
i wrote the template and loaded it in to the server and the the sprites did not play correctly.
on my computer, for testing, i was using a newer version.
so i updated the server. then on our graphic we went to change the location bug. and i ran in to this behavior.

like i said it works fine if i do it from the play command in the official client.
the client or server (not sure witch) calls an update when it is played.
it is only when i call update by its self.

and i can use the update function form a browser debug counsel.

but you do not see this behavior? so i am even more perplexed.
you are on the lts version. i switched to a master build to get the ability to use my sprites.

i will try it with 2.3.3_LTS

that is my goto verison any way. but i have a hole new issue there with system audio.
we use Dante and have had a lot of issues with that of late

it all kind of started with this template and and a need to incorporate ndi.
we have about 10 servers. and when we moved some to the 2.3.3 we had client issues with older server models. some running on windows 7 (don’t fix it if it ain’t broke)
too much back story i know.

I have not seen the behaviour you are experiencing - but I have mostly implemented CSS or Greensock library based animations, and have never had a reason so far to tackle sprite sheets. Many years ago I did create my own animation core for canvas operations, mostly because I could not find if the other libraries used requestAnimationFrame() callbacks, and I needed a proof of concept template as soon as available.

It is the server that invokes update() when the client requests a CG play operation. Server behaviour updated when version 2.1 was released. Before that Javascript required a function play(user_string). In 2.1 and later the play function needs no parameters so just function play(), the server calling update(user_string) then calling play(). As my users still have some server 2.0.7 instances in operation (as you said, if it is working - leave alone!) I have to code for both server type behaviours, checking if a string is passed to play(), and calling update if string is present.

If I am correctly reading you postings, your code is making the call to update() - you are not invoking function update from the standard client (F6 key). The client only invokes update() as part of play(). If so, it makes me think that you may have two definitions for a token named update - one being the global scope update(user_string) and the second being the same token name but this is not a function. Hence the error message you reported in post 5 of this thread.

The core Javascript engine searches for a token name, intially in the current local context, and if that fails it looks at the global context. I think the global context can be explicitly written as window.update(user_string), and I therefore think you can force the resolution in your code by explicitly calling window.update(string_value) from your code.

no my code does not call the update function.
i do that from the client (F6 key).
that is when i get the error in the server.

if i do add a line of code to call it it works.
if i call it form the browser it works.
if i press play (F2 key) it gets called.

when i add the white space to the function name i.e update () {…} it works as expected
if there is no white spare i.e. update() {…} i get erros when i call it. from the client.

i do have a privet bool in a function named update. may be that is an issue.
and i have a function called GFX_update()