Sign in to follow this  
Followers 0
Sheep_Wizard

Returning values in a array

6 posts in this topic

Im gonna try explain this the best I can

 

So I was to be able to edit the values of an array in a function and then return them to the original thread. Here is an example:

array_test()
{
    test = [];
    test[0] = 1;

    while(1)
    {
        add_array(test);
        iPrintLn(test[0]);
        wait 0.5;
    }
}

add_array(num)
{
    num[0]++;
    return num[0];
}

The problem is that the thread 'array_test' it still sees 'test[0]' being == 1

 

Is there a way I can make it update 'test[0]'

 

To help explain better this currently prints ' 1,1,1,1...' but I want it to print '1,2,3,4...'

0

Share this post


Link to post
Share on other sites

Im gonna try explain this the best I can

 

So I was to be able to edit the values of an array in a function and then return them to the original thread. Here is an example:

array_test()
{
    test = [];
    test[0] = 1;

    while(1)
    {
        add_array(test);
        iPrintLn(test[0]);
        wait 0.5;
    }
}

add_array(num)
{
    num[0]++;
    return num[0];
}

The problem is that the thread 'array_test' it still sees 'test[0]' being == 1

 

Is there a way I can make it update 'test[0]'

 

To help explain better this currently prints ' 1,1,1,1...' but I want it to print '1,2,3,4...'

im pretty sure you cant pass by reference/pointer in gsc 

 

PFAjGVg.gif

0

Share this post


Link to post
Share on other sites

 

 

Logically you can do this. But why? What is your end goal here?

0

Share this post


Link to post
Share on other sites

Logically you can do this. But why? What is your end goal here?

I need to edit the values of lots of different arrays depending on a certain outcome. Doing it in a function would save me having to right out the changes to each array for each outcome.

0

Share this post


Link to post
Share on other sites

I need to edit the values of lots of different arrays depending on a certain outcome. Doing it in a function would save me having to right out the changes to each array for each outcome.

As @@Bear already said, GSC doesn't support reference arguments so you'll just have to store the return value into your array variable.

arrayTest() {
	test = [];
	test[0] = 1;

	for(;;) {
                // Store return value into the variable
		test = addArray( test );
		iPrintLn( test[0] );
		wait .5;
	}
}

addArray( num ) {
	num[0]++;
	// Return entire array instead
	return num;
}

Though, this is majorly inefficient and really doesn't have any point to it.

0

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0