Jump to content
Sign in to follow this  
rbesca

looping over an integer array with itoa()

Recommended Posts

i@iterations = len(chs("../NETWORK_CONTROLLER/c2p_querstrbn"));
s@myArray = chs("../NETWORK_CONTROLLER/c2p_querstrbn");

i[]@myintArray = {};
s[]@mystrArray = {};

//remove spaces from string array, get len() of string array


if (i@iterations >2)  {
    i@iterations += 1;
    i@iterations /= 2;
    }

    
//create arrays from preselection

int i;
for(i=0; i < i@iterations*2; i++) {

i@stringtointeger = atoi(s@myArray[i]);
append(i@myintArray, i@stringtointeger);
}

// remove spaces from int Array

i[]@cleanArray = i@myintArray[0::2];

// convert back to string to read in with copy to points target points later

for(i=0; i < i@iterations; i++) {

s@integertostring = itoa(s@mystrArray[i]);
append(i@mystrArray, s@integertostring);

}

hey all, vex noob here. I am trying to append values from an integer array to a string array.

looping over array entries with atoi works fine to extract the strings and append them to an int array. but the other way around using itoa gives me this error:

 

Warning:     Errors or warnings encountered during VEX compile:
             /obj/geo1/pointwrangle4/attribvop1/snippet1: Call to undefined array index operator 'int string[][int]'.    (33,53).
Error:       Error in VOP 'snippet1'.
Warning:     Errors or warnings encountered during VEX compile:
             /obj/geo1/pointwrangle4/attribvop1/snippet1: Call to undefined array index operator 'int string[][int]'.    (33,53).
Error:       Vex error: /obj/geo1/pointwrangle4/attribvop1/snippet1: Call to undefined array index operator 'int string[][int]'.         (33,53)

 

i'll try to sum up the context quickly: I have a controller node where I can enter the points I want to copy objects to. now when I copy to point 0 1 2 3, another copy node should copy other objects to points 4 5 6 7. when I enter 0 1 2, the other copy should go to 3 4 5 etc.

Edited by rbesca

Share this post


Link to post
Share on other sites

while I don't completely understand what you are going for, but this 

s@integertostring = itoa(s@mystrArray[i]);

 should probably be this, as you aferall want to convert int to string

s@integertostring = itoa(i@cleanArray[i]);

but I doubt it will help your code as you are clearly dealing with strings and want output as a string not string array, what exactly are you trying to do? 

Why would someone enter only sequential 0 1 2 3, what if user enters 0 3 4 6? what would you expect the rest to be? 1 2 5 7? what if there is not 8 points in the geo? sounds like too many assumptions

usually you want to use groups for this, you pick your points as group A and then one copy uses group A and another !A

if however you still want to pursue VEX then have a look at functions like split() and join() to avoid unnecesary code, also you may want to use variables instead of attribute bindings unless you want the values to be atually output into an attribute

Edited by anim
  • Like 1

Share this post


Link to post
Share on other sites

I'm sorry I said that wrong, yes I originally have a string not a string array. 

if someone would enter 0 3 4, i would want to copy to 0 1 2 and 3 4 5.

so take a string, len(), clean the spaces and use that length to create two lists of that length but one should be offset by the length. then I want to use that string as my target points

image.png.d8bed4978b82958a470faf4c8b5f3208.png

image.png

image.png.cb48a97430cf23f41f410cfb9811849f.png

 

Edited by rbesca

Share this post


Link to post
Share on other sites

why not just taking integer number then?

if user enters 3, one group will be 0 1 2  and another 3 4 5

ir in another words if you have integer paramerer "n"

then one group field will be: 0-`ch("n")-1`

and another: `ch("n")`-`ch("n")*2-1`

  • Thanks 1

Share this post


Link to post
Share on other sites

I honestly just didn't think of using groups... this looks like a much better way to do this

Share this post


Link to post
Share on other sites

don't have to be groups, just directly put it in target points group field of Copy SOPs

if you want to create groups first you may find Group By Range handy as you are just creating 2 range groups

Share this post


Link to post
Share on other sites

okay so the user input could still be 0 3 4 with using a ch() it doesn't need to be a direct input of 3, I can just get the length of my string, make it an int "n" parameter and set as I wish and then get that value with ch("../mynode/"n"")?

Share this post


Link to post
Share on other sites

alright I'm using point() to get my iteration count now and it's working :) thank you tomas, have a safe time!

 

I think what made this so complicated for me was that I forgot that you can type in 0-3 instead of 0 1 2 3 which makes this a lot easier to type the way you did instead of trying to do unnecessary things with arrays and vex

Edited by rbesca

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×