private String useObstacleVariables(String s, int frame) {
		if (!(model instanceof AtomicModel))
			return s;
		AtomicModel m = (AtomicModel) model;
		if (m.obstacles == null)
			return s;
		int n = m.obstacles.size();
		if (n <= 0)
			return s;
		int lb = s.indexOf("%obstacle[");
		int rb = s.indexOf("].", lb);
		int lb0 = -1;
		String v;
		int i;
		RectangularObstacle o;
		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, "Obstacle " + i + " does not exist.");
				break;
			}
			v = escapeMetaCharacters(v);
			o = m.obstacles.get(i);
			if (frame < 0) {
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.x", o.x * R_CONVERTER);
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.y", o.y * R_CONVERTER);
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.vx", o.vx * V_CONVERTER);
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.vy", o.vy * V_CONVERTER);
			} else {
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.x", o.rxryQ.getQueue1().getData(frame) * R_CONVERTER);
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.y", o.rxryQ.getQueue2().getData(frame) * R_CONVERTER);
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.vx", o.vxvyQ.getQueue1().getData(frame) * V_CONVERTER);
				s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.vy", o.vxvyQ.getQueue2().getData(frame) * V_CONVERTER);
			}
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.width", o.width * R_CONVERTER);
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.height", o.height * R_CONVERTER);
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.friction", o.friction);
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.elasticity", o.elasticity);
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.hx", o.getHx() * 1000);
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.hy", o.getHy() * 1000);
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.externalfx", o.getHx() * 1000); // deprecated
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.externalfy", o.getHy() * 1000); // deprecated
			s = replaceAll(s, "%obstacle\\[" + v + "\\]\\.custom", o.custom);
			lb0 = lb;
			lb = s.indexOf("%obstacle[");
			if (lb0 == lb) // infinite loop
				break;
			rb = s.indexOf("].", lb);
		}
		return s;
	}