function CreateAPI(hostAddress = "" as string) as object
api = CreateObject("roAssociativeArray")
api.HostAddress = hostAddress
api.ClientID = ""
api.ReceiveResponse = API_Receive
api.Call = API_CALL
return api
end function
function debugAPI()
print "Creating API object"
api = CreateAPI("http://192.168.128.110/jsonrpc/")
print "Checking validity"
if api = invalid
print "API is invalid"
else
print "API is valid"
end if
print "Calling API(";api.HostAddress;")" <--- This line crashes
result = api.Call("Server.RegisterClient") <--- This one too
print "Execution successful"
end function
print "Calling API(";api.HostAddress;")" <--- This line crashes
print "Calling API(" + Chr(34) + ";api.HostAddress;" + Chr(34) + ")"
result = api.Call("Server.RegisterClient") <--- This one too
"RokuChris" wrote:
It would be helpful if you shared the text of the crash(es), but off the top of my head...print "Calling API(";api.HostAddress;")" <--- This line crashes
Probably the nested quotes are the problem. Try something like:print "Calling API(" + Chr(34) + ";api.HostAddress;" + Chr(34) + ")"result = api.Call("Server.RegisterClient") <--- This one too
This would initiate a call to a function called API_CALL(). Is that function defined somewhere?
print api.HostAddress
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...3W3UR/pkg:/source/appMain.brs(23)
023: print api.HostAddress
function CreateAPI() as object
api = {}
return api
end function
function debugAPI()
print "Creating API object"
api = CreateAPI()
api.HostAddress = "test" <-- This line crashes... It should just be an
empty roAssociativeArray right? Why would this fail?
print "Checking validity"
if api = invalid
print "API is invalid"
else
print "API is valid"
end if
print "Execution successful"
end function
Creating API object
Checking validity
API is valid
Execution successful
"RokuChris" wrote:
The crash indicates that your api variable is invalid for some reason.
But that latest snippet works fine for me. I get this on the console:Creating API object
Checking validity
API is valid
Execution successful
"Rek" wrote:
I tried making a new project and running that snippet, and it works for me there too. I suspect the error message is completely wrong, and I need to look somewhere else.