Hi @DreamAlchemist,
just to make sure - you are using a Text TOP?
You could switch the Text parameter into expression mode and type an expression that references the MQTT DAT’s cell you are interested in:
1 if op('mqttclient1')[1,0] == 'Game1' else 0
More practically you would want to parse the message right when it arrives in the MQTT Client DAT’s onMessage
callback.
Here for example you get a bunch of variables you can use that represent the message:
# dat - the OP which is cooking
# topic - topic name of the incoming message
# payload - payload of the incoming message
# qos - qos flag for of the incoming message
# retained - retained flag of the incoming message
# dup - dup flag of the incoming message
What is always useful is to open up the Textport (Dialogs>Textport) and then write a debug
statement into the callback like this:
def onMessage(dat, topic, payload, qos, retained, dup):
debug('dat:', dat, 'topic:', topic, 'payload:', payload, 'qos:', qos, 'retained:', retained, 'dup:', dup)
return
When a message is received, you should now get a printout in the Textport with all the values of the variables printed out.
From here you will see if the value you want to check is in your payload or if it’s the topic. If it’s the payload, a script to place the value in the Text TOP could look like:
def onMessage(dat, topic, payload, qos, retained, dup):
textVal = 0
if payload == 'Game1':
textVal = 1
op('text1').par.text = textVal
return
Oftentimes it might make sense to prepare a Table DAT for the different types of messages you might receive, store the values in there and then retrieve them in the displaying operators (like your Text TOP) by referencing that Table DAT.
We can look at that more when you get this running though.
For a good introduction to scripting in TouchDesigner, have a look at our Curriculum at
learn.derivative.ca
there are great short videos that convey the basic concepts of python in TouchDesigner.
cheers
Markus