Return function

If we had a way to cut executing a function short early, it will allow us to stop nesting conditionals as much. We've seen some crazy nested conditionals in the examples, it would be nice to have an alternative method that is cleaner in the editor.

I'll edit in an example soon.

Edit: Haha, almost 3 weeks later and I remember this request


// Without return, 3 levels
on tick do
  cooldown--
  if cooldown == 0 then
    // Fire a bullet
    cooldown = 20
  end
end

// With return, 2 levels
on tick do
  cooldown--
  if cooldown != 0 then
    return
  end
  // Fire a bullet
  cooldown = 20
end


Edit 2:
It's been added! Playdate PulpScript

3 Likes

Yes please! Early returns allow for cleaner code and better readability.

Ah the march to the right. Yes this would be great if it's not already in.

it's been added a while ago.

done

You can call the command above to return from a function.

1 Like

Great! Hmm it would be good if there was a tag for feature requests in progress or completed...

No way to break out or continue in a loop yet though. That would still be a great addition.