Return doesn't actually return?

duggold
10 Jun 2012, 19:12
I was spinning my wheels for a while and finally figured out the problem is the return command doesn't actually exit the function. This seems pretty counter-intuitive. Why was this done and how CAN I exit a function prematurely?

Pertex
10 Jun 2012, 20:17
duggold wrote:...how CAN I exit a function prematurely?

You can't do it at the moment.

sgreig
11 Jun 2012, 00:42
A clever programmer friend of mine says it's possible to fudge a break command in a language that doesn't have any by modifying the iterator variable in the loop. So if you have a script that loops until the variable i = 10 or until another condition is met, simply add code to the section where the condition is met that changes i to 20 and it will exit the loop prematurely.

Not sure if I explained it in a way that makes sense, but I've used it since his suggestion and it works well.

duggold
11 Jun 2012, 02:34
Yes, the issue is it's not a loop. I have a check at the beginning of the function to see if there's anything in the room. If not, I wanted to simply return. I restructured it to just use else commands etc. to just skip all the code. Just seems inefficient and really odd that return really doesn't return.