This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Read Custom values from Script
#1
Hello Dear,
I want to use the custom value in the script, How?
Best Regards,
Reply
#2
Can you explain more what you want to do? Do you want to create custom value on a object via script or instead of object value use custom value in scripting?
------------------------------
Ctrl+F5
Reply
#3
See this: https://forum.logicmachine.net/showthrea...9#pid14379
Reply
#4
(05.09.2023, 12:44)Daniel Wrote: Can you explain more what you want to do? Do you want to create custom value on a object via script or instead of object value use custom value in scripting?

Hello Dear,
Yes the second one

(05.09.2023, 12:49)admin Wrote: See this: https://forum.logicmachine.net/showthrea...9#pid14379

Could I use it with Tag_Data = grp.tag(Used_Tag)
or should I use  grp.find
Best Regards,
Reply
#5
Then look on the admin link.
------------------------------
Ctrl+F5
Reply
#6
grp.find will return a single object properties table, grp.tag will return a table with all objects that have the specified tag so you must iterate this table and then use the sample code if you want to use grp.tag instead of grp.find, so yes possible but requires a small change in the sample code…
Reply
#7
hello Erwin,
Code:
for i, obj in ipairs(Tag_Data) do
log(obj)
.....

the custom values are not in the log table!

Quote:* table:
["decoded"]
  * bool: true
["disablelog"]
  * number: 1
["pollinterval"]
  * string:
["datahex"]
  * string: 01
["units"]
  * string:
["value"]
  * bool: true
["comment"]
  * string:
["updatetime"]
  * number: 1693924997
["datatype"]
  * number: 1
["readoninit"]
  * number: 0
["data"]
  * bool: true
["id"]
  * number: 65878
["address"]
  * string: 32/1/86
["export"]
  * number: 0
["name"]
  * string: TEst For Test-2
["tagcache"]
  * string: Office VRV ON/OFF

How could I achieve that instead of adding a grp.find ?
Best Regards,
Reply
#8
This won't work without an extra grp.find or a db query:
Code:
json = require('json')
objs = grp.tag('my_tag_name')

for _, obj in ipairs(objs) do
  enums = db:getone('SELECT enums FROM objects WHERE id=?', obj.id)
  enums = json.decode(enums)

  log(enums)
end
Reply
#9
Thank You admin
you have the solution as always, is there a Guide how to use the  db query:  
Also thank you Erwin for pointing on this solution.
Best Regards,
Reply


Forum Jump: