Queueing events in VNyan

VNyan is a VTubing software used for animating a 3D model for streaming and content creation. I’ve been using it for the last couple of months because of some of its features such as the nodes system.

Nodes are a way to visually script events based on Twitch, WebSockets or whatever is supported in the app. Lately I’ve been thinking about doing a bit more and giving the possibility to just go wild and queue events such as model swap.

Version 1.2.1b is required, the update introduces a wizard that can be skipped if you already have VNyan setup.

What is a queue?

We want to push items to the end of the array and take items from the top of it.
This is what we call first in first out. It’s the absolute basic idea behind the queueing of events.

The plan

I want to setup commands to do stuff and have them be processed in order with a short delay between each commands. The commands will be normal Twitch chat commands to make things easier.

We will need two things:

  • An interval timer that will be triggered to run when the queue is not empty;
  • The event handling that will pop the first element on the top of the queue and run it;
  • The logic needed to tell when the loop must run and what it is stopped.

In my example I will have two commands:

  • !throwApple which will throw an apple at me;
  • !throwDuck which will throw a rubber duck at me.

This can work for doing model swaps but will require a bit more thought and care since you might want to animate that (through effects or transformations) and you will want to take into account the loading delay.

Queuing in VNyan

First of all we need to create the logic that will handle the events, the entry point will be a trigger and it will start a timer that will call that trigger again until the queue is empty.

The events will be handled by conditions that will be checked, if true you’ll apply you action and you’ll delay another call of the event loop. If false you’ll just flag the event queue as finished and not call it again (until another command is called).

Each command will push an element into the queue and it if the event queue isn’t running it will call the event trigger and setup a flag.

 

It’s important to note that we use theĀ Enqueue Text Array and theĀ Dequeue Text Array.

Prior to this version dequeueing an item was done by using an Ordered Execution node that would get an item from the queue and remove the item by index.