Jump to content

looping over an integer array with itoa()


rbesca

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
Link to comment
Share on other sites

  • rbesca changed the title to looping over an integer array with itoa()

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
Link to comment
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
Link to comment
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
Link to comment
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"")?

Link to comment
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
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...