Supersimple Vex question

   3199   5   1
User Avatar
Member
861 posts
Joined: Oct. 2008
Offline
OK, this is my very first vex code, so sorry for the superbasic question but here it goes:

I want to get a string attribute with the neighbours of each point. So, for point 0 it may be:

“0 1 2 5”

for point 2 it may be:

“1 0 54 4”

etc, etc.

The below code doesn't work. I think it tries to write an array and it doesn't convert it into a string. Now, I saw there is atoi to convert a string to an int , but nothing to convert an int or array to a string?


sop
my_sop()
{
int n;
string s = “”;
n = getneighbours( ptnum, 0 );
addattribute(“Neighbors”, n, “type”, “string”);
}
--
Jobless
User Avatar
Member
2199 posts
Joined: July 2005
Online
try

sprintf(string format)
The trick is finding just the right hammer for every screw
User Avatar
Member
861 posts
Joined: Oct. 2008
Offline
Hmm, but sprintf requires a string and prints to the console? How can I get it to swallow an integer and write a string attribute?

Sorry, it must be blindly obvious. I feel like a cyclops…
--
Jobless
User Avatar
Member
2199 posts
Joined: July 2005
Online
sprintf

not

printf
The trick is finding just the right hammer for every screw
User Avatar
Member
861 posts
Joined: Oct. 2008
Offline
Ooh, I see. Thanks Simon. This worked:

sop
my_sop()
{
int n;
string s = “”;
n = getneighbours( ptnum, 0 );
s = sprintf(“%s”,n);
addattribute(“Neighbors”, s, “type”, “string”);

}
--
Jobless
User Avatar
Member
861 posts
Joined: Oct. 2008
Offline
I have another, related question. I don't see an obvious way of doing this, and it may not be possible, but can we create an n*n matrix in vex, perhaps in such a way that it can be picked up by Python later on down the node chain?

I'm thinking of creating an adjacency matrix from my neighbour data.
--
Jobless
  • Quick Links