-
Notifications
You must be signed in to change notification settings - Fork 19
[Suggestion] Multiple returns #2
Comments
I thought a little about this in the context of error messages. With App Inventor and Blockly, we had/have an explicit philosophy of prioritizing ease for the beginner over the desires of experienced programmers, since we expect the latter to use textual programming languages. I was planning to stick to that philosophy unless you can convince me otherwise. My thinking is that experienced programmers could use Lua and would prefer to do so. Debugging requires messing with the Lua code anyway. That said, I was thinking of providing support for error messages. For example, the code generated for: if turnRight would be: result, error = turnRight()
if result
: The special variable "error" would contain the most recent error message. Actually, the code would really be: function turnRight_()
result, error = turnRight()
return result
end What do you think? |
I do understand, and agree with that philosophy, unfortunately however with ComputerCraft there is nothing that an unexperienced programmer doesn't want to do, for example rednet messages, they're always finding an excuse to use them, and their format is the following local senderId, message, distanceSent = rednet.receive() as you can see, requires multiple variable declarations. Obviously helper functions could be made for them in order for it to work, but I've noticed that a large amount of the community tend to simply copy/paste without actually learning anything from it, so my opinions on these matters are slightly conflicting to what I would normally say compared to what I think with ComputerCraft. Side-note: you've overrode the global |
On Mon, Nov 4, 2013 at 8:19 PM, Josh Asbury notifications@github.comwrote:
|
On Mon, Nov 4, 2013 at 8:19 PM, Josh Asbury notifications@github.comwrote:
Does that mean that the API is obsolete? I've never used the API (or even Thanks. Ellen |
Not at all! The rednet API is designed for communication of data between computers. Methods of communication we have is Wireless Modems and Wired Modems via Network/Peripheral cables. In previous versions of ComputerCraft when we did not have network cables, the rednet API was able to function over RedPower2 bundled cables as a wired (and thus more distance) connection. All that note is stating is that we can no longer use Bundled cables from RP2, because we have our own cable and RP2 isn't updated for the last few versions of Minecraft. We can however still interact with RedPower2 cables (if it were updated) through the redstone API, via |
Lua is a weird language, it can actually return multiple values from functions as individual return values like so
Which when called like so means that you only gain one of the values
As such to pickup all values you must either do
or
I think adding the ability to do this in blockly-lua could be handy, especially when starting to build event sensitive programs.
The text was updated successfully, but these errors were encountered: