How do I get SCORM to initialize a second time?

Some web browsers will fail when loading a SCORM lesson a 2nd time. The failure will be that it will not properly initialize with the LMS. Internet explorer works fine but Safari and Chrome requires that the user exit any LMS tabs and then quit the browser.

Currently the newest version of Scorm actually reports back that it has initialized even though it has not. No further player settings can be saved or retrieved even thought the app is running fine.

2 Answers

2

Hi @Dragonhill

My english isn’t good, so patience :stuck_out_tongue:

I don’t know why, but when you start again a SCORM instance, the Unity MainThread is the same thread where SCORM is initialized, and this is wrong… I got a fast solution, i hope this works for you.

In waitForInitializeFinish( ), while the variable “Initialized” is equal to false will question for the life of the thread, if the thread is dead and the “Initialized” still false, will create another thread with different id. And “timesAttempted” is like a limit, use whatever value you want, im using 6 attempts.

    public IEnumerator waitForInitializeFinish()
	{
		UnityEngine.Application.ExternalEval("DebugPrint(\"Things work! (wait for init)\");" );
		
		System.Threading.ThreadStart start = new System.Threading.ThreadStart(Initialize_imp);
		System.Threading.Thread t = new System.Threading.Thread(start);
		t.Start();
		
		int timesAttempted = 0;
		
		while( Initialized == false){
			
			if(!t.IsAlive)
			{
				t = new System.Threading.Thread(start);
				t.Start();
				timesAttempted ++;
			}
			
			if(timesAttemped >= 6)
				yield return null;
			
			yield return new WaitForSeconds(0.5f);
			UnityEngine.Application.ExternalEval("DebugPrint(\"Things work! (waiting...)\");" );
		}
		
		UnityEngine.Application.ExternalEval("DebugPrint(\"Things work! (done)\");" );
		GameObject.Find(ObjectName).BroadcastMessage("Scorm_Initialize_Complete",SendMessageOptions.DontRequireReceiver);
	}

And in Initialize_imp( ) a little change…

    private static void Initialize_imp()
	{
		if(!CheckThread())
			return;
		
		Initialized = false;
		
		ScormBridge = new Unity_ScormBridge(ObjectName,"ScormValueCallback");
		ScormBridge.Initialize();
		
		try{
			if(ScormBridge.IsScorm2004)
			{
				//WebLog("IsScorm2004");
				StudentRecord = new Scorm2004.DataModel();	
				ScormDeSerializer deserializer = new ScormDeSerializer(StudentRecord);
				StudentRecord = (Scorm2004.DataModel)deserializer.Deserialize(ScormBridge);
			}else
			{
				//WebLog("IsScorm1.2");
				Scorm1_2.DataModel tempStudentRecord = new Scorm1_2.DataModel();	
				ScormDeSerializer deserializer = new ScormDeSerializer(tempStudentRecord);
				tempStudentRecord = (Scorm1_2.DataModel)deserializer.Deserialize(ScormBridge);
				StudentRecord = ScormVersionConversion.DataModel.Translate(tempStudentRecord);
			}
			//WebLog("Initialize_imp() = true");
			Initialized = true;
		}catch(Exception e)
		{
			UnityEngine.Application.ExternalCall("DebugPrint", "***ERROR***" + e.Message + e.StackTrace  + e.Source );
		}
	}

Regards

@david_ah3

Thanx david!.. I’ll try this out when I get a chance… my current solution was to start a session… then log it out an then restart a second right after that and everything works fine now… yea… that’s a brute force solution and not very elegant.

BTW, your English is fine for me… thanx again!

~D