Yikes, you don't use schedules like that, and that while loop will definitely cause a crash. This is usually how a schedule is structured in a basic function:
function functionName(%args)
{
if(isEventPending($functionNameLoop))
cancel($functionNameLoop);
//code...
//more code...
//schedule(int milliseconds, object, function, arguments);
$functionNameLoop = schedule(1000,0,functionName,%args);
}
This will cause the function to call itself every 1000 milliseconds, which is 1 second.