Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

I have the retail EV3 kit and have created a function with in and out numeric parameters.

While using the [in] params seem quite straight forward, it seems that I can only set the [out] param once. Dragging a second wire from a constant or variable will not connect when I place them.

Can I only set an [out] param once?

Does setting the [out] param act like the "return" keyword?

I have had a look around, but there is very little help on the EV3 My Blocks at present.

Bad, but simple example:My Blocks return example

Please note that this is a simplification of the problem, and in this case I could set x to -1 or have another case in the sensor switch to set x to -1. I am trying to explorer the limitations of EV3 My Blocks out parameters.

share|improve this question
    
Can you post a screenshot of the function? –  dfrevert May 18 at 21:57

3 Answers 3

up vote 1 down vote accepted

Can I only set an [out] param once?

Yes. You cannot tell it to be 2 different values at the same time. This applies to any block, not just the output block.

Does setting the [out] param act like the "return" keyword?

Not really. The return keyword in most (if not all) programming languages causes the function to exit, which is not the case here. It just allows you to assign the output value (or values - you can have more than one output parameter).

share|improve this answer

I think this is as close as you'll get (other than the constant being set to 99 instead of -1). You end up with 2 output parameters instead of one. If you really want only one output, you'll need some logic to determine which to output.

A similar MyBlock that returns two output parameters

share|improve this answer

I don't think I showed a great example. Using David Lechner's advice I changed the code to be more like the below:enter image description here

I use x to store my return value, and when loop 02 is finished, x is copied to the output param.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.