Luascript Service
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Luascript Service
Hi All,
I want to write a service in Lua script, for the below conditions:
Accepts three inputs – a (integer), b(minute, integer), and c (integer, 1-3)
- Sets d property to zero, for a greater than 0. Hold it at zero if a > 0, tasker should not increment or change d property, if a > 0.
- Places text message in LSR log window as below:
- if C value is 1 then “Green”
- if C value is 2 then “Yellow”
- if C value is 3 then “Red"
How to do this ? I am getting an error while writing this as i am new to lua.
Thanks,
Aditya
- Labels:
-
Coding
-
Connectivity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aditya,
Can you show us the code you already have? I think with the logic you described you can do this with a while loop with a repeat function. If you can show me how far you got I should be able to help get it working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
First defined the service as below:
serviceDefinitions.RemoteService (
input { name="a", baseType="INTEGER" },
input { name="b", baseType="INTEGER" },
input { name="c", baseType="INTEGER" },
output { baseType="NOTHING" },
description { "Values" }
)
services.RemoteService = function(me, headers, query, data)
if not a then
return 400, "You must provide the 'a' parameter"
else
return 200, me.setProperty("d",0,0,0)
end
I have proceeded like this but getting in error in this piece of code itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aditya,
I'm assuming that you're working from this tutorial:
Defining and Implementing Custom Services at the Edge
If that's the case, you're probably getting one of two errors.
1. lua: user.lua:15: 'end' expected (to close 'function' at line 9) near <eof>
-This is because you are missing an 'end' to close the function. You have one to close the if statement, but the function is still open
2. attempt to index global 'serviceDefinitions' (a nil value)
stack traceback:
user.lua:1: in main chunk
-This is because the data in the service you defined is provided from outside the script (from the Edge service.) Essentially, there is nothing input into the input lines leaving it empty, hence the complaint of a nil value.
For this reason, the lua script in the example from the tutorial will not work outside the context of the Edge server. It might be a good idea to go though all the steps of that tutorial and set up an Edge Enhanced Thing to work with if you're not doing that already.
Note: I also found this tutorial on scope very useful when researching this issue: Tutorial: Scope for beginners | Corona Labs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aditya,
Any update on this? Was my post helpful?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks Jeremy!!
Can you please help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
can anyone help on this
