super.function();

Discussions about Coding and Scripting
Post Reply
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

super.function();

Post by Rakiayn »

could someone tell me how this exactly works?
what happens if you put it in your code? what happens if you place code before or after it?
I do have an idea what it does but im not sure
Meindratheal
Average
Posts: 61
Joined: Thu Jun 03, 2010 3:53 pm

Re: super.function();

Post by Meindratheal »

From what I can tell, it calls the function as it is defined in the superclass.

It's basically there so you can add code to a function without needing to rewrite what was already defined in the superclass.
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: super.function();

Post by Rakiayn »

yes I thought so.
But I want to know exactly hoe it works.
if you place code before super.function();. will it first call the code ,and then the code of the superclass?
or does it mean that the code replaces the code of the superclass?
Meindratheal
Average
Posts: 61
Joined: Thu Jun 03, 2010 3:53 pm

Re: super.function();

Post by Meindratheal »

I'm sure it's treated as a normal function, so it will be called in the order you have it.

Super.function() is there just so you don't have to copy/paste the super function into your class, give it a name and then call that instead.
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: super.function();

Post by Rakiayn »

allright thanx :tu:
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: super.function();

Post by Rakiayn »

one more question
if you use local properties in a function.
will they also travel to the childclass function if it calls super.function(); ?
Meindratheal
Average
Posts: 61
Joined: Thu Jun 03, 2010 3:53 pm

Re: super.function();

Post by Meindratheal »

Hmm, for that I have no idea. I don't really code much o_O

The best way to find out would be to make a test package with two scripts, and test it that way.
Bloeb
Experienced
Posts: 95
Joined: Tue Apr 06, 2010 11:07 am

Re: super.function();

Post by Bloeb »

I think it's a good idea to read about scope in programming, it's one of the basics you need to know. I don't know the specifics about UScript, but I'm almost positive that variables or references with a local identifier have local scope. This means that you can't use the variable or reference outside the function (or block, depending on the language) it's declared in.

- Programming Scope
- Local Scope
User avatar
anth
Adept
Posts: 257
Joined: Thu May 13, 2010 2:23 am

Re: super.function();

Post by anth »

Your question isn't really unrealscript related. Calling a super function is possible in all object oriented languages. I'd strongly recommend reading a book (or a tutorial) about object oriented programming (or perhaps java which is similar to unrealscript in many ways and a very popular OO language). And as Bloeb says, local variables are only valid in the scope in which they were defined. This means that if you call a super function, its local variables will only exist in the scope of that super function. They will not be valid in the scope of the function that called the super function.
Post Reply