I’ve been trying to write some class code, and this has been driving me up the wall trying to find a workaround for the last few days. Here’s some basic agent code to outline the problem:
`const URL = "https://www.google.com"
class myClass
{
val = 0
function processResponse(incomingDataTable)
{
server.log("Code: " + incomingDataTable.statuscode + ". Message: " + incomingDataTable.body)
this.val = 200 // BOOM.
}
function log(logMessage)
{
local extraHeaders = {}
local request = http.get(URL, extraHeaders)
this.val = 100
request.sendasync(processResponse)
}
}
local x = myClass()
x.log("Hello, World!")
server.log("object val = " + x.val)`
Running the above results in (somewhat edited to remove tagging):
[Agent] object val = 100
[Agent] Code: 200. Message: [...truncated...]
[Agent] ERROR: the index 'val' does not exist
[Agent] ERROR: at processResponse:10
It seems to me that the sendasync() method needs to be sending a hidden first scope parameter (ie.- this), but it isn’t. Is there a way around this I’m not figuring out?