Grimmy's Recent Forum Activity

  • Yes, that only works on PC. It doesn't do anything on mobile. God knows why not. :(

  • Still no luck. I even tried doing this script which works perfectly fine on PC but on device it always returns as connected..

    function NetworkTest(runtime)
    {
    	var xmlHttp = new XMLHttpRequest();
    	xmlHttp.open( "GET", "https://www.mysite.com", true );
    	xmlHttp.setRequestHeader("Access-Control-Allow-Origin", "*");
    	xmlHttp.send();
    	
    
    	xmlHttp.onerror =function ()
    	{
    		runtime.callFunction("Change_Connection_Status",0);//NOT CONNECTED
    	}
    	
    	xmlHttp.onload =function ()
    	{
    		
    		runtime.callFunction("Change_Connection_Status",1);//CONNECTED
    	}
    	
    }
    
  • It seems like an on completed Ajax event gets run even when there is no internet connection. Is that right?

    I'm trying to make a reliable way to detect internet connection on device and I would have thought the Ajax On Completed request wouldn't trigger without a connection but apparently not.

    I am currently at a loss of how to detect internet connection on device. I've spent 2 days on this so far.!?!?

    Anyone know the answer? Thanks

  • I cant share the capx but the events to do with the predict function script above look like this:

    [PREDICT]

    | Local number Variable1‎ = 0

    ----* On function 'Do_Sensight_Request'

    ----* Parameter 'image' (String)

    -----> Functions: Call Hide Results

    -----> Functions: Call Reposition Last Photo

    -----> System: Wait for previous actions to complete

    -----> System: Set isDoingPrediction to 1

    -----> LastPhoto: Load image from UserMedia.SnapshotURL (Keep current size, cross-origin anonymous)

    -----> Functions: Call AnimateSnapshot

    -----> Run JavaScript:

    file_in= await runtime.assets.fetchBlob(localVars.image);

    predict(runtime);

    // we got the data now top the loader and update

    ----* On function 'Event_Got_Data'

    -----> Run JavaScript: GetResult(runtime);

    -----> JSON: Parse JSON string returned_data

    -----> System: Set isDoingPrediction to 0

    -----> Functions: Call Update Results

    ----* On function 'Update Results'

    -----> System: Set layer "Results" Visible

    -----> System: Set layer "Loader" Invisible

    -----> ResultText_1: Set text to JSON.Get("0.label")&" : "&JSON.Get("0.score")&"%"

    -----> ResultText_2: Set text to JSON.Get("1.label")&" : "&JSON.Get("1.score")&"%"

    -----> ResultText_3: Set text to JSON.Get("2.label")&" : "&JSON.Get("2.score")&"%"

    ----* On function 'Hide Results'

    -----> System: Set layer "Loader" Visible

    -----> System: Set layer "Results" Invisible

    Hopefully that should be enough to get you through..

  • None of these methods are working for me on device. I have 'always connected' regardless if I am actually connected or not and I'm doing an AJAX check to

    "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"

    every 2 seconds. (I tried various other websites too)

    Like everyone said the browser event doesn't work on a device and nor does the PlatformInfo.ConnectionRTT method work (always returns 0 on device).

    Regarding CORS if I add a header "Access-Control-Allow-Origin" "*" then I just get Not COnnected all the time.

    I also tried various plugins of which all had other compatibility issues.

    I would have thought this was a very commonly used feature in most mobile games, so I'm surprised there isn't an obvious solution.

    Where to turn next?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • SOLVED

    Even if nobody replies, I think that just the act of posting a question here seems to bring about some kind of mystical epiphany.:)

    In case anyone should ever need this; to change this to an asynchronous function which runs while your game is still running, it should be something like this:

    function apiPostRequest(request, body,runtime) {
    	var xmlHttp = new XMLHttpRequest();
    	
    	xmlHttp.open( "POST", baseApiURL + request, true );//TRUE indicates asynchronous
    	xmlHttp.setRequestHeader('Content-Type', 'application/octet-stream');
    	xmlHttp.setRequestHeader('X-Auth-token', token);
    	
    	xmlHttp.onload =function (e)
    	{
    		
    		console.log("Resp: "+xmlHttp.responseText);
    		//alert ("Resp :"+xmlHttp.responseText);
    
    		resp=xmlHttp.responseText;
    		results=JSON.parse(xmlHttp.responseText);
    		
    		runtime.globalVars.returned_data = xmlHttp.responseText;
    		runtime.callFunction("Event_Got_Data");//call event sheet function once complete
    
    	}
    
    	xmlHttp.send(body);
    	
    }
    
  • I'm currently doing a XMLHttpRequest which works fine but holds up the rest of the game until the data is returned.

    How would I keep the game running while the request is going on in the background?

    Current request looks like this:

    function apiPostRequest(request, body) {
    	var xmlHttp = new XMLHttpRequest();
    	xmlHttp.open( "POST", baseApiURL + request, false );
    	xmlHttp.setRequestHeader('Content-Type', 'application/octet-stream');
    	xmlHttp.setRequestHeader('X-Auth-token', token);
    	xmlHttp.send(body);
    	console.log("Resp: "+xmlHttp.responseText);
    	
    	resp=xmlHttp.responseText;
    	
    	return xmlHttp.responseText;
    }
    
  • You do not have permission to view this post

  • SOLVED.

    Instead of calling

    GetResult();
    

    I need to call..

    GetResult(runtime);
    
  • Just to explain further in the most simple example:

    I call this function from a JS block..

    var resp;//this is a variable which gets adjusted with other script code
    
    function GetResult(runtime)
    {
    	alert("Looky here: "+resp);//This prints fine as expected! The resp is full of lovely data.
    	
    	runtime.globalVars.returned_data = resp;//The global value is not set in the runtime according to the debugger
    }
    

    and I get the error: TypeError: Cannot read property 'globalVars' of undefined

  • Its got this in the same script. Is that what you mean? ..or do I need something else?

    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    	
    });
    
  • After getting some data (xmlHttp.responseText) from the web I now need the result to be put back into my event sheet.

    My global variable is called 'returned_data' (its a string)

    I tried runtime.globalVars.returned_data = xmlHttp.responseText but my global variable will not change despite the fact that the alert with the same data displays perfectly, as does the console log with the returned data. I need to get the returned data back to the event sheet for further manipulation.

    Here is the JS script

    function apiPostRequest(request, body) {
    	var xmlHttp = new XMLHttpRequest();
    	xmlHttp.open( "POST", baseApiURL + request, false );
    	xmlHttp.setRequestHeader('Content-Type', 'application/octet-stream');
    	xmlHttp.setRequestHeader('X-Auth-token', token);
    	xmlHttp.send(body);
    	console.log("Resp: "+xmlHttp.responseText);//PRINTS RESULT PERFECTLY
    	alert ("Resp :"+xmlHttp.responseText);//PRINTS RESULT PERFECTLY
    	
    	runtime.globalVars.returned_data = xmlHttp.responseText;//DOES NOTHING - Global ver is not changed
    	
    	return xmlHttp.responseText;
    }
    
Grimmy's avatar

Grimmy

Member since 20 Nov, 2012

Twitter
Grimmy has 2 followers

Trophy Case

  • 12-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Great Comment One of your comments gets 3 upvotes
  • Email Verified

Progress

17/44
How to earn trophies