private String useTriangleVariables(String s) {
		int n = view.getNumberOfInstances(TriangleComponent.class);
		if (n <= 0)
			return s;
		int lb = s.indexOf("%triangle[");
		int rb = s.indexOf("].", lb);
		int lb0 = -1;
		String v;
		int i;
		TriangleComponent triangle;
		while (lb != -1 && rb != -1) {
			v = s.substring(lb + 10, rb);
			double x = parseMathExpression(v);
			if (Double.isNaN(x))
				break;
			i = (int) Math.round(x);
			if (i < 0 || i >= n) {
				out(ScriptEvent.FAILED, "Triangle " + i + " does not exist.");
				break;
			}
			v = escapeMetaCharacters(v);
			triangle = view.getTriangle(i);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.x1", triangle.getVertex(0).x * R_CONVERTER);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.y1", triangle.getVertex(0).y * R_CONVERTER);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.x2", triangle.getVertex(1).x * R_CONVERTER);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.y2", triangle.getVertex(1).y * R_CONVERTER);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.x3", triangle.getVertex(2).x * R_CONVERTER);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.y3", triangle.getVertex(2).y * R_CONVERTER);
			s = replaceAll(s, "%triangle\\[" + v + "\\]\\.particlecount", triangle.getParticleCount());
			VectorField vf = triangle.getVectorField();
			if (vf instanceof ElectricField)
				s = replaceAll(s, "%triangle\\[" + v + "\\]\\.efield", vf.getIntensity());
			else if (vf instanceof MagneticField)
				s = replaceAll(s, "%triangle\\[" + v + "\\]\\.bfield", vf.getIntensity());
			else {
				s = replaceAll(s, "%triangle\\[" + v + "\\]\\.efield", 0);
				s = replaceAll(s, "%triangle\\[" + v + "\\]\\.bfield", 0);
			}
			lb0 = lb;
			lb = s.indexOf("%triangle[");
			if (lb0 == lb) // infinite loop
				break;
			rb = s.indexOf("].", lb);
		}
		return s;
	}