Object.method returns false (instead of Lang.Method instance)

It is probably a rookie mistake, but I can't make a simple Communications.makeWebRequest()work. I tried to use the official example from here. The only thing I changed is, that I use the variable responseCallback in the request call. When I debug the code, the value of this variable is false, it seems like Object.method cannot find :onReceive. (I'm currently testing on 4.0.9, as I tried on newer versions, and the app crashes before I could get to a breakpoint to debug.) I'm sure I'm missing something fundamental...

  • Thanks for the response, I haven't used any context, as far as I can understand, it is optional, and only needed when the request is made with it. But my reference(?) to the callback is false.

    This is the relevant part of my code:

    class Foo {
        function onReceive(responseCode as Number, data as Null or Dictionary or String) as Void {
            
        }
    
        function doSomething() {
    
            ....
    
            var responseCallback = method(:onReceive);  
                           
           
            BREAKPOINT
        }
    }

    When I reaach BREAKPOINT, the value of responseCallback is false (Lang.Boolean).

  • Ok, if I do

    		var cb=method(:onReceiveF);				
    		Comm.makeWebRequest(
    	       	url,
    	       	param,
    	       	options,
    	       	cb);

    it works fine. The callback is 

    function onReceiveF(status,data) {
    ...
    }

    you want to check if status==200.  if it's not, data will be null.
    with a 200, you'll see something in data if your server sends something back.
    Are you requesting json data?
  • Thanks, unfortunately I don't get to a place to check the status, as makeWebRequest throwws an exception. Hope this screenshot clarifies my issue:

    I changed every relevant thing in my code to adhere to your snippets (removed typing, changed identifiers). 

    (And yes, I plan to fetch a json, and thank you again.)

  • In this case, here's what I have for options:

    		var options = {
    			:method => Comm.HTTP_REQUEST_METHOD_GET,
    			:headers => {"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED},
    			:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    		};

    Using your url, here's what I see with a println for status and data in onReceiveF

    s=200 {Szebi=>2, Cas/=>8, Kalapács=>7, Captain Morgen=>14, Smidlus Maximus=>1, RunnerMate=>14, Kuvik=>9, Baptisia=>1, TOTALin(n)a=>1, Csíkszereda=>9, CsíkiMëdvë=>6, Cailín miongháire=>8, Nymphaeaceae=>1, Merida=>6, Sziki=>1, Vigyori=>10, AlpenFrau=>7, Szamuráj=>4, Parketta=>9, Vikida=>5, Cemitirmo=>1, Hilja=>9, Tibeti=>9, Bögre=>4, Dr. Senkiházi=>5, Esőmanó=>10, PARTYzán!=>6, Luinil=>7, i□=>11, Baboš=>1, Csülök=>9, FehérVillám=>1, Mór=>11, Nórima Atar=>12, Palko=>2, Puddding=>1, Vera=>1, VolleyballGuy=>2, Yavanna=>12}

  • changed the responsetype, but cb is still false, and same behavior. I'll try the same thing on a different system tomorrow. It is also strange, that newer SDK don't even work, and I can never see outputs. Maybe the issue is with some of my old libs or something on this computer (Ubuntu 20.04 LTS). Thank you, I'll get back on this tomorrow. I wanted to make a simple fun project (get a json list of str:int, order them by the value, and display them as a top list in a widget) to learn the basics, and got stuck at the first step :-D

  • Installed the SDK on Ubuntu 23.04, creating the callback "pointer" now works for the SDK versions I tested. So it seems, the issue was with the environment. (I stil lget 404 but that's a step forward :-)) Thanks for al the help.