Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Often times in interfaces we have this use case where we have a datasource that will give us information with a sequence of incrementing IDs. For instance the IMAP email protocol is an example of this.

It’s nice to control where you start from and keep incrementing the value as we go forward. The COUNT library solves this problem.

 Import the COUNT library into your project.

See Import Library if you need a refresher on how to do it.

 Create a custom number field called 'NextId' and set it to the value 1 in your card.
 The COUNT library solves this problem by giving a convenient interface to GET/SET a custom field value

Remember Custom Fields the values for these are stored on disc in JSON. This means we can load and save them programmatically.

This is what this library does.

 local NextId = COUNTget("NextId") is how we fetch the data

This is how we get the data from a custom field called NextId.

local NextId = COUNTget("NextId") 
 COUNTset("NextId", NextId) is how we set it.

So this saves the new value of the custom field in the custom field value file.

COUNTset("NextId", NextId) 
 It means we can see the NextId in the card view of the component - and we can set it too!

 This is a complete little program to increment a custom number field
require "COUNT.COUNT"

function main(Data)
   --Poll the component every 5 seconds
   component.setTimer{delay=5000}
   local NextId = COUNTget("NextId")
   NextId = NextId+1
   COUNTset('NextId', NextId)
end

This is a very useful pattern for lots of ‘feeder’ interfaces.

  • No labels