Help with mobile compatibility

I have this code for accessing a database to pull question information for our game. The code works in the editor and in PC builds, however mobile and web builds do not. I am new to both mobile and database programming so I am not sure where the hangups are. Any tips or advice is greatly appreciated.

using UnityEngine;
using System.Collections;

namespace QuestionStuff
{
	public class Question : MonoBehaviour
	{
	
		private string formRandomizer = "1";
		private string questionURL = "www.g2the3rd.com/questiongrabber.php";
		private string hash = "5f9901fc60b769b523d0dd8e79b3fe08";
		private string question, answerone, answertwo, answerthree, answerfour, answerfive, answersix, correct;
	
		public Question ()
		{
			this.question = "";
			this.answerone = "";
			this.answerthree = "";
			this.answerfour = "";
			this.answerfive = "";
			this.answersix = "";
			this.correct = "";
		}
		
		public void GenerateQuestion ()
		{
		
			char[] delimiters = new char[1];
			delimiters [0] = char.Parse ("$");
		
			WWWForm questionForm = new WWWForm ();
			questionForm.AddField ("myform_hash", hash);
			int newRandomQuestion = Random.Range (1, int.Parse (formRandomizer));
			formRandomizer = newRandomQuestion.ToString ();
			questionForm.AddField ("myform_randomizer", newRandomQuestion);
		
			WWW getQuestion = new WWW (questionURL, questionForm);
		
			while (!getQuestion.isDone) {
				Debug.Log (Time.time);
			}
		
			string[] data = getQuestion.text.Split (delimiters);
		
			this.question = data [0];
			this.answerone = data [1];
			this.answertwo = data [2];
			this.answerthree = data [3];
			this.answerfour = data [4];
			this.answerfive = data [5];
			this.answersix = data [6];
			this.correct = data [7];
		}
		
		public string GetQuestion(){
			return this.question;	
		}
		
		public string GetCorrectAnswer(){
			return this.correct;	
		}
		
		public string GetAnswer(int answerNumber){
			switch(answerNumber){
				
			case 1:
				return this.answerone;
				
			case 2:
				return this.answertwo;
				
			case 3:
				return this.answerthree;
				
			case 4:
				return this.answerfour;
				
			case 5:
				return this.answerfive;
				
			case 6:
				return this.answersix;
				
			default:
				return "Invalid number.";
			}
		}
	}
}

I know I put the hash and php script addresses but they are just temporary so I’m not concerned.

An easy way to debug is to have an onscreen text field and output to that field each step it got up to, you’ll at least find out which part you are failing at :slight_smile:

You can also use the actual debug console to print out too

The code compiles and works in PC mode. But on the web and on the phones it does not. I assume that the issue has to do with permissions or the use of functions that are not allowed in mobile/web.

just a guess, but try using a proper url:
questionURL = “www.g2the3rd.com/questiongrabber.php”; →
questionURL = “http://www.g2the3rd.com/questiongrabber.php”;

No luck, when I read your post I was thinking " fully qualified domain name" but no dice. I really wish we could figure this out.

As @codeoverlord said, to be able to debug this you/we need more information on where the hangup is. Add more debug print-outs, check the log. Also this code is not how you would normally use the WWW object. Normally you would ‘yield’ for the result. Unity - Scripting API: WWW

If you don’t yield you will put the main thread into a loop while fetching data from the server and this is very bad for many reasons. Also, it could be that on some platforms the isDone() property is never set due to the async nature of the WWW call if you don’t use yield.

/martin