Evaluating the newest cell of a FIFO DAT

Hello all,

I want to have a certain phrase from my Twitch chat to initiate a trigger within TD. I’ve been able to connect to my channel and chat with Elburz’s websocket DAT script. I have appended the chat text to a FIFO DAT, which is all great so far!

Now I’m trying to read the most recent row contents in the FIFO DAT and change a Constant CHOP to a value of 1, which then feeds into a Trigger CHOP. I should mention I suck at Python. I’m just curious what the actual syntax would be. I know I need and if statement, I’m just not sure what syntax is used to evaluate the most recent row contents in a FIFO DAT.

So after a bit of experimentation with the following code in the original websocket DAT, I was able to have a trigger activate when a specific string was passed through chat.

if user_message.find("test1") >=0:
		op('constant1').par.value0 = 1
	elif user_message.find("test1") !=0:
			op('constant1').par.value0 = 0

The problem I now have is I’m unsure of how to “void” the most recent message, so to speak. If I type ‘test1’ and activate the trigger, then type ‘test1’ once again, it trigger won’t activate a second time.

Would using the FIFO DAT help in this? Is it really even necessary?

EDIT:

So…pulsing is definitely the answer.

op('constant1').par.value0.pulse(1, seconds=1)

But I guess my original question still stands: is there a way to evaluate the most recent cell in a FIFO DAT?

EDIT: THIS IS THE HARD WAY! See comments below! While this will work, fifo has its own callbacks already.

Make a DAT Execute DAT pointing to your fifo. Use this onTableChange callback as a starting point:


def onTableChange(dat):
	lastRow = dat.row(dat.numRows-1) # this gets the last appended row
	cellInRow = lastRow[0] # this gets the first column
	stringInCell = cellInRow.val # this gets the actual string instead of the cell
	
	# the above can be combined into:
	lastCell0 = dat[dat.numRows-1, 0].val
		
	# here's the logic part where you can search for specific strings or whatever
	if stringInCell: # put any logic you want here
		debug(stringInCell, lastCell0) # do whatever you want here. This prints to textport

Also, on a site-note: The fifoDAT has its own callbacks. So if you want to react to a new cell (the latest row added) use the onNewRow funtion.

1 Like

Isn’t the FIFO DAT callback better than using a DAT Execute DAT because the FIFO DAT callback will run once for every row that is added, even if several rows are added in one frame, whereas the DAT Execute DAT approach only gets one row per frame at most, meaning you may miss some new messages, unless you do some other tricks.

1 Like

Ack! How did I miss that?

Yes, use the fifo DAT’s onNewRow callback, found in the DAT attached below fifo when you create it. All the info for the new cells is in the “cells” argument. The one gotcha is to get the actual string from the cell as opposed to the cell object, use .val

def onNewRow(dat, rowIndex, cells):
	if 'test1' in cells[0].val: 
		op('constant1').par.value0 = 1

Thank you all for the info! Ivan, I appreciate that snippet of code. I was messing around with the onNewRow function but couldn’t quite get it to work. Now that I have the syntax, that shouldn’t be a problem!

1 Like