Java ScriptEngine-Like step by step execution

Is there a way to execute a code like the ScriptEngine does, but step by step ?

For exemple :

    if (contact(player,self)){
    	callCinematics("forest.png", "face1.png","SALUT!");
    	teleport("test",0,5,5);
    } else {
    	print("A");
    }

I want to execute this code step by step, when I call my function eval(), first, it will check the condition, and wait for the second call.
If the first call return true, the second call eval the “callCinematics(…);”, or “print(“A”);” if the first call return false.
If the first call return false, the third call of eval will do nothing, until I call another function that restart all the call.

I don’t know if i’m very understandable ^^’.