Community
SCI Programming => SCI Syntax Help => Topic started by: gumby on November 08, 2010, 10:07:34 PM
-
Is this even possible? I've re-read the tutorials here & the Studio help files, but haven't turned anything up - nothing talks about pointers or passing-by-reference that I can find.
-
What's a pointer?
-
It's a reference to a variable or object. In my case I want to access an object from within a procedure. In my case, I'd like to pass in a reference/pointer to an object rather than the object itself. I guess I could just make the object accessible globally & then I wouldn't have to pass anything in, but that could get messy...
-
What's a pointer?
Lol, don't ever take up advanced C/C++ programming. Pointers can be a nightmare if you can't wrap your head around them or how to use them (I sure can't).
I don't think the SCI language is capable of dealing with pointers. I believe I heard this mentioned officially from troflip or Brian in the past.
-
I don't think the SCI language is capable of dealing with pointers. I believe I heard this mentioned officially from troflip or Brian in the past.
That's kinda what I figured, but I wanted to make sure that I wasn't missing something somewhere. I guess it's global variables & objects for me!
-
Well, you can get a pointer using the @ operator. The problem is, you can't dereference a pointer again, only pass it to kernel functions.
So it depends on what you want to do with it: While integers or arrays are out of the question (in SCI0, anyway), strings will work.
But reading the thread again, I think you're not realizing that when you pass an object to a subroutine,
you are indeed passing a pointer to it. That's how setMotion calls work - by taking a pointer to the motion class you want to use,
cloning it and then using the clone for the duration of the motion.
-
I think you're not realizing that when you pass an object to a subroutine, you are indeed passing a pointer to it.
Yep, you're right. I looked at SetJump for example and it does use a pointer as it's first argument. And now that I think about it some of string kernel functions utilize pointers in their calls as well.
Well, you can get a pointer using the @ operator. The problem is, you can't dereference a pointer again, only pass it to kernel functions
...
cloning it and then using the clone for the duration of the motion.
In my case, I want to be able to manipulate the original object within the procedure; using a clone would not preserve the changes to the original object.
EDIT: I guess I could return the clone and set the original to it (of course this would only work with a single object, but it's something...)
-
In my case, I want to be able to manipulate the original object within the procedure; using a clone would not preserve the changes to the original object.
It is not the case that object values are "magically" restored once you return from a subroutine call. An object is always passed to subroutines by reference. I'm afraid I can't see the problem.
-
I understand now. Since objects are passed by reference, I am working with the original object. Sorry for the dense moment... and thanks for getting me back on track.