Author Topic: Pass variable by reference/pointer  (Read 7490 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

Pass variable by reference/pointer
« 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.


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Pass variable by reference/pointer
« Reply #1 on: November 09, 2010, 11:25:44 AM »
What's a pointer?
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Pass variable by reference/pointer
« Reply #2 on: November 09, 2010, 12:34:41 PM »
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... 
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline MusicallyInspired

Re: Pass variable by reference/pointer
« Reply #3 on: November 09, 2010, 06:00:30 PM »
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.
Brass Lantern Prop Competition

Offline gumby

Re: Pass variable by reference/pointer
« Reply #4 on: November 09, 2010, 07:20:10 PM »
Quote
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!
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline lskovlun

Re: Pass variable by reference/pointer
« Reply #5 on: November 13, 2010, 12:48:17 PM »
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.

Offline gumby

Re: Pass variable by reference/pointer
« Reply #6 on: November 13, 2010, 01:31:16 PM »
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...)
« Last Edit: November 13, 2010, 01:36:04 PM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline lskovlun

Re: Pass variable by reference/pointer
« Reply #7 on: November 13, 2010, 02:03:09 PM »
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.

Offline gumby

Re: Pass variable by reference/pointer
« Reply #8 on: November 13, 2010, 03:25:56 PM »
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.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.066 seconds with 22 queries.