Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reference as return type.
#1
Is it possible to get a reference to an object through return type?
How do i do that?

for instance i want to make a simple function -
object findemptycell()
{
object o;
int i=0;
while (true)
{
o = retobject(i);
if (o != null)
{
if (o.category ==PowerCell)
{
if (o.position.x != nan)
{
message("sdsd");
return o;
}

}
i++;
}else break;
}
}
But this does not work.
#2
The only problem I see with your code is that the function may not return a value at all. Try adding a "return null;" at the end. Other than that, I think this should work.
#3
Yeah. I just got some kind of a glitch.

Now i am curious about - is there some kind of garbage collector.

extern void object::Spider2()
{
int[] q;
q = qw();
message(q[2]);

}

public int[] qw()
{
int testarray[]={1,2,3,4,5};

return testarray;
}


If am i correct - with every call of function a brand new array will be created?
And last but one will stay in memory without link on it. - with means wasted memory?
Can you advise me about this things?
#4
You don't need to worry about any memory management in CBot - the interpreter will handle everything for you (unless there is a bug, which is very likely because of how terrible the CBot interpreter code is). The array will be destroyed as soon as all references to it go out of scope (in this case - at the end of Spider2 function)
#5
But copy of this will be still active?
And a really little question. What type category are? I mean what type of variable can contain it?
#6
(07-04-2016, 05:14 PM)clop1000 Wrote: But copy of this will be still active?
It will be removed automatically when nothing in the program uses it anymore.

(07-04-2016, 05:14 PM)clop1000 Wrote: What type category are? I mean what type of variable can contain it?
Categories are just int constants.


Forum Jump:


Users browsing this thread: 3 Guest(s)