FoozleCC's Forum Posts

  • Hey Everyone - Anyone else face challenges getting their games to load from a mobile phone using the Facebook app?

    The game I am working on is uploaded to their web hosting and I am able to run from browser on my laptop with no issues but can almost never get it to load on my phone. I end up closing the app and relaunching it multiple times before it manages to actually load and on my most recent build I cannot get it to load at all.

    Any ideas on what may be causing this?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Was able to figure this out..

    First, I had an error in assigning the uploadURL from the response.

    uploadURL = response.data.UploadDetails.UploadUrl;

    should have been

    uploadURL = response.data.UploadDetails[0].UploadUrl;

    While using fetch should probably work as well, ended up getting it to work with XMLHttpRequest.

    I got the following code to successfully push the data to playfab as a file.

    In the example below I am putting DataTest in but in my use case I have a large array of tile map data that I am storing. In place of DataTest in my example I set my tile map data equal to a global variable and send that within the send instead.

    General flow is that once the data is ready to send, call PF_InitiateFileUploads passing the entity information received from login which I had stored in a global variable in the event sheet. In the callback, send data to url received with XMLHttpRequest, initiate trigger to event sheet with status = "ready", then followup with with a call to FinalizeFileUploads.

    //InitiateFileUploads
    //https://api.playfab.com/documentation/Data/method/InitiateFileUploads
    function PF_InitiateFileUploads(f_EntityId,f_EntityType,f_EntityTypeString){
    	
    	var request = {
    		"FileNames": [
    			"mapData"
    		],
    		"Entity": {
    			"Id": f_EntityId,
    			"Type": f_EntityType,
    			"TypeString": f_EntityTypeString
    		}
    	}
    	PlayFabDataSDK.InitiateFileUploads(request,onInitiateFileUploadsResponse);
    }
    //FinalizeFileUploads
    //https://api.playfab.com/documentation/Data/method/FinalizeFileUploads
    function PF_FinalizeFileUploads(f_EntityId,f_EntityType,f_EntityTypeString){
    	
    	var request = {
    		"FileNames": [
    			"mapData"
    		],
    		"Entity": {
    			"Id": f_EntityId,
    			"Type": f_EntityType,
    			"TypeString": f_EntityTypeString
    		}
    	}
    	PlayFabDataSDK.FinalizeFileUploads(request,onFinalizeFileUploadsResponse);
    }
    
    function onInitiateFileUploadsResponse(response, error) {
    	var uploadURL;
    	var DataTest={
    		posX: 45,
    		posY: 23
    	};
    
    	if (response !== null) {
    		console.log("InitiateFileUploads response received")
    		console.log("InitiateFileUploads response: " + JSON.stringify(response));
    
    		uploadURL = response.data.UploadDetails[0].UploadUrl;
    		
    		console.log(uploadURL)
    		
    		var xhr = new XMLHttpRequest();
    		xhr.open("PUT", uploadURL, true); // true : asynchrone false: synchrone
    		xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    		xhr.send(JSON.stringify(DataTest));
    		xhr.onreadystatechange = function () {
    			if (this.readyState === 4) {
    				console.log(this.responseText)
    				var status = "ready";
    				console.log("status: " + status)
    				myIruntime.callFunction("ES_initiateFileUploads_Results",status)
    			}
    		};
    	} else if (error !== null) {
    		console.log("InitiateFileUploads error received")
    		console.log("InitiateFileUploads error: " + JSON.stringify(error));
    	}
    }
    function onFinalizeFileUploadsResponse(response, error) {
    	if (response !== null) {
    		console.log("FinalizeFileUploads response received")
    		console.log("FinalizeFileUploads response: " + JSON.stringify(response));
    	} else if (error !== null) {
    		console.log("FinalizeFileUploads error received")
    		console.log("FinalizeFileUploads error: " + JSON.stringify(error));
    	}
    }
  • This is likely just my ignorance of javascript but wanted to see if someone could help with the correct way to upload a file to playfab once the upload url is received.

    The below will successfully use the InitiateFileUploads api to receive a response with an upload url. I am already logged in and getting the appropriate entityId / type and passing it in. I would like now to do a put using that url to upload sample data which I call DataTest below into an entity file on playfab.

    What is the proper way to do this in javascript? Does it need to be encoded? I am attempting to use fetch in an async function but am I simply approaching it incorrectly? Any help is appreciated!

    Also, I was able to get their setObjects api working correctly which could also be used to store small sets of data as demo'd below but I am interested in storing larger amounts of information which requires the use of an entity file.

    The closest documentation on playfab is below under the entity files section:

    api.playfab.com/docs/tutorials/entities/getting-started-entities

    //InitiateFileUploads
    //https://api.playfab.com/documentation/Data/method/InitiateFileUploads
    function PF_InitiateFileUploads(f_EntityId,f_EntityType,f_EntityTypeString,mapData){
    	
    	var request = {
    		"FileNames": [
    			"mapData"
    		],
    		"Entity": {
    			"Id": f_EntityId,
    			"Type": f_EntityType,
    			"TypeString": f_EntityTypeString
    		}
    	}
    
    	PlayFabDataSDK.InitiateFileUploads(request,onInitiateFileUploadsResponse);
    }
    
    
    function onInitiateFileUploadsResponse(response, error) {
    	//console.log(gMapData);
    	var uploadURL;
    	var DataTest={
    		posX: 45,
    		posY: 23
    	};
    
    	if (response !== null) {
    		console.log("InitiateFileUploads response received")
    		console.log("InitiateFileUploads response: " + JSON.stringify(response));
    
    		uploadURL = response.data.UploadDetails.UploadUrl;
    		
    		loadFile(uploadURL,DataTest)
    		
    	} else if (error !== null) {
    		console.log("InitiateFileUploads error received")
    		console.log("InitiateFileUploads error: " + JSON.stringify(error));
    
    	}
    }
    
    async function loadFile(uploadURL,data){
    	var payload = data;
    	var otherParam={
    		headers:{
    			"content-type":"application/json; charset=UTF-8"
    		},
    		body:payload,
    		method:"PUT"
    	};
    	const response = await fetch(uploadURL,otherParam);
    	const jsonData = await response.json();
    }
  • You do not have permission to view this post

  • Solved my own problem...

    Was getting the syntax mixed up.

    I just looped through my array in java script calling the below and it worked.

    runtime.objects."your array name here".getFirstInstance().setAt(val, x, y, z)

  • Been having some fun using javascript but I am not sure what the best method is to pass an array I created in a script back to an array object in the Event Sheet.

    Is there a way to directly set the size and the values using IArrayInstance? I read the below but I am not sure what the appropriate syntax is.

    construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/plugin-interfaces/array

    I have already figured out how to pass information back to the event sheet using runtime.callfunction. Is this required to pass a string of the array back to be handled in the event sheet somehow to become an array?

    Thanks in advance for any advice!

  • Awesome!

    Thank you so much! worked liked a charm. I went down such a worm hole looking for solutions after banging my head on this.

    Cheers

  • Thanks for the quick reply!

    I was attempting to implement something similar to this. I have what is needed on the event sheet but what I run into is that "runtime" is not defined. I am not positive on what the best way is to ensure it is defined, any suggestions?

    Below is current callback function:

    var LoginCallback = function (result, error) {
     if (result !== null) {
    		console.log("It worked! Log");
    		var sessionTicket = result.data.SessionTicket;
    		runtime.callFunction("LoginWithCustomID_Results",sessionTicket)
    		//return "TESTING" //this doesn't work
     } else if (error !== null) {
    		console.log("It didn't worked! Log");
     return "Something went wrong with your first API call.\n" +
     "Here's some debug information:\n" +
     PlayFab.GenerateErrorReport(error);
     }
    }
  • Hello all - new to Construct 3 but have been enjoying the engine so far. I was working through some examples and successfully used the PlayFab javascript SDK for LoginWithCustomID. What I am not sure however, is what the best way within construct to pass the results from a javascript file back into event sheets.

    My initial thought was to use the runtime.callFunction to an eventsheet function that accepted the results as an argument but runtime is not defined. The line below generates a promise but I am not sure how best to await / get the results back from the call back:

    PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback)
    

    full .js example (this is called by an event sheet function and in dev tools I can see the results, just don't know how to appropriately return it):

    function DoExampleLoginWithCustomID(f_Title_ID,f_Custom_ID){
     PlayFab.settings.titleId = f_Title_ID;
     var loginRequest = {
     // Currently, you need to look up the correct format for this object in the API-docs:
     // https://api.playfab.com/documentation/Client/method/LoginWithCustomID
     TitleId: PlayFab.settings.titleId,
     CustomId: f_Custom_ID,
     CreateAccount: true
     };
    
    
    	PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback)
    	
    }
    
    var LoginCallback = function (result, error) {
     if (result !== null) {
    		console.log("It worked! Log");
    		
    		return result //this doesn't work
    		
     } else if (error !== null) {
    		console.log("It didn't worked! Log");
     return "Something went wrong with your first API call.\n" +
     "Here's some debug information:\n" +
     PlayFab.GenerateErrorReport(error);
     }
    }
    

    Thanks for any help you can offer!

    Tagged: