Jump to content

[SOLVED]VEX Not All Code Paths Return Value?


Recommended Posts

Hi All,


I have a small piece of VEX code that will not compile. I keep getting the message that not all code paths return a value. I don't see how this is possible because there is only one return and the return is referencing a variable that is already initialized.

float string_point_attribute(string attribute; int id) {
    string result = "";
    int success = 0;
    string attribute_value = pointattrib(geoself(),attribute, id, success);
    if (success) {result = attribute_value;}
    return result;

What is wrong with my code?

Edited by Atom
Link to comment
Share on other sites

I think the problem is your implicitly casting a string to a float (I'm assuming you can do this but I've never tried), and VEX is casting result = "" to nothing rather then a value of zero, as there not really the same thing.


Changing it to string result = "0", might fix that, but something like 

int success = 0;
string attribute_value = ....
if (success)
    return (float)attribute_value;
    return 0; // or any value you know is incorrect and can test for

may be a better choice, if I understood the intent of your function.

Link to comment
Share on other sites


That was it. I feel silly. I cloned this string version of the function from the float version and did not notice the type of the return value.


The error message could be a little clearer. Like "Return type does not match function definition." or something...

Edited by Atom
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...