Jump to content

Passing an array as an argument in VEX? / Looking for 1-to-1 tutoring.


Ocelote

Recommended Posts

Hi everyone!


 


I'm currently struggling with this: 


 


Is there a way of passing an array as an argument, fill it with integers and then return that array to be used by another function?


 


Something like this?


 


int pt_numbers_array[];


 


int create_points(vector v1; int array[]; int total_pts) {


 


        vector new_pos1 = v1;


 


        for (int i = 0; i < total_pts; i++){


 


            int pt1 =  addpoint(geoself(), new_pos1);


            array = pt1;


            new_pos1 += {0,1,0};


        }


        return array[]; 


        


}


 


create_points(@P,pt_numbers_array[],5);


 


 


Actually, this is not my only question. So, is it posible to get some personal VEX training with someone? I don't wan't to abuse the forum...


 


 


Thanks in advance.

Link to comment
Share on other sites

Guest mantragora

You don't need to return it from your function. It's passed by reference so it will be modified. Run this in Detail mode:

#define PRINT(val, text) printf("numbers %s: %d\n", text, val)
 
vector CENTER = set(0, 1, 0);
int numbers[];
 
void AddPoints(const vector pos; const int maxcount; int refarray[]) 
{
    vector newPos = pos;
 
    for (int i = 0; i < maxcount; i++)
    {
        int currentNumber =  addpoint(geoself(), newPos);
        refarray[i] = currentNumber;
        newPos += {0, 1, 0};
    }
}
 
PRINT(numbers, "before");
AddPoints(CENTER, 3, numbers);
PRINT(numbers, "after");
Edited by fântastîque Mântragorîè
  • Like 1
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...