Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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)
How to do this ? I am getting an error while writing this as i am new to lua.
Thanks,
Aditya
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.
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.
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
Aditya,
Any update on this? Was my post helpful?
Thanks Jeremy!!
Can you please help me
can anyone help on this