private void save(Script[] mainScripts, String file) throws IOException
	{
		// for (Script script : endScripts)
		// add(this.allScripts, script);
		// Collections.reverse(this.allScripts);
		
		// for (Script script : this.allScripts)
		// this.used.put(script, false);
		// for (Script script : this.allScripts)
		// dfs(script);
		
		// ArrayList<Script> scripts = new ArrayList<Script>();
		// for (Script script : this.order)
		// scripts.add(script);
		
		/*
		for (int i = 0; i < scripts.size(); i++)
		{
			Script script = scripts.get(i);
			for (Script nextScript : script.dependentScipts)
			{
				ArrayList<Condition> conditions = new ArrayList<Condition>(Arrays.asList(nextScript.beginConditions));
				conditions.add(new ConditionScript(i));
				nextScript.beginConditions = conditions.toArray(new Condition[0]);
			}
		}
		*/
		
		ArrayList<Script> scripts = new ArrayList<Script>();
		for (Script script : mainScripts)
		{
			scripts.add(script);
			this.add(scripts, script);
		}
		
		for (Script script : scripts)
			for (ScriptType type : ScriptType.values())
				if (Script.classes[type.ordinal()] == script.getClass())
				{
					script.type = type;
					break;
				}
		for (Script script : scripts)
			for (Condition condition : script.beginConditions)
				setType(condition);
				
		JsonWriter writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(file)));
		writer.beginObject();
		writer.name("scripts").beginArray();
		for (Script script : scripts)
			script.write(writer);
		writer.endArray();
		writer.endObject();
		writer.close();
	}