Jump to content

expanding a variable in vector(string type)


Recommended Posts

Hi, I am learning to write my own custom expression funtion.

Guess I didn't want to bother the List with such a kindergarten question.

Is there any way to expand a variable in a vector(string type)?

vector My_Function(val1, val2, val3)

{

vector Buffer = vector("[val1, 2, 3, val2, 1, val3, 7]");

return Buffer;

}

and since vector() is a string type, I couldn't assign my own number into the val*...

Oh, I am not doing this for any project actually. Just as an exercise.

Thanks.

Link to comment
Share on other sites

It's a little strange that you'd need a 7-component vector. I know this is just

an exercise, but I don't think you'd see this very often in practice. :(

Unless you're building an array - but even then the *caller* must be able to use

it somehow...

Anyway; for 3- or 4- component vectors you can use the vector3() and vector4()

functions directly:

return vector3(val1, val2, 3);

return vector3(val1, val2, val3, 4);

In your case, you're returning 7 components so you need to build the string for

the generic vector() function. One way would be to use strcat(), like this:

return vector( strcat(strcat(strcat(strcat(strcat(strcat("[",val1),", 2, 3, "),val2),", 1, "),val3),", 7]") );

Ugly! :wacko:

But AFAIK, the expression language doesn't have an sprintf() function yet...

-----

Mario.

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.

Guest
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...