Search the Community
Showing results for tags 'nextuntil'.
-
Hello, I'm stuck with a nextUntil() use I can't figure out. The following function works if I use the commented part instead of the last 2 lines (with nextUntil). function checkStreak($player) { // Set Ambassador skill if necessary $ok = 1; $streak = 0; /* $lastEvents = $player->get("name=history")->find("template=event, sort=-date")->not("task.name=donated|donation|absent, limit=10"); */ /* foreach ($lastEvents as $e) { */ /* if ($ok == 1) { */ /* if ($e->task->HP >= 0) { */ /* $streak++; */ /* } else { */ /* $ok = 0; */ /* } */ /* } */ /* } */ $lastEvent = $player->get("name=history")->children("template=event, sort=-date")->not("task.name=donated|donation|absent")->first(); $streak = $lastEvent->nextUntil("task.HP<0")->count(); return $streak; } But I know it's ugly and... I sometimes wish I had a tutor to help me improve my coding style In words, what I'm doing is : - Check the last events recorded for a 'player' - I want to check the number of positive events in a row (before a negative occurs) - My function gets the last 10 events (the limit to get a bonus) and checks each one, but stops if it encounters a negative event and return the streak. BUT : looking at the API cheatsheet (thanks @soma), I've noticed this nextUntil() which I would like to use... but my use always returns 0 If someone can understand why and help me improve on that one, I would appreciate. Thanks ! By the way, feel free (if you have a few minutes) to give me advice on how to improve those foreach() I feel like I'm overusing...