HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[vJASS] Structs, Stub and Parent.

08-27-2009, 06:09 PM#1
Anachron
Hello guys there!

I am having a small problem...

Collapse JASS:
struct A
     public static method test takes nothing returns nothing
         call thistype.test2()
     endmethod

     public stub method test2 takes nothing returns nothing
     endmethod
endstruct

struct B extends A
    public static method test2 takes nothing returns nothing
        call BJDebugMsg("Test2! in child")
    endmethod
endstruct

My question is, when I have this:

Collapse JASS:
   local A ins = A.create()
   local B ins2 = B.create()

   call ins2.test()

Why does it call the method "test2" of A, isntead of b's method?

Edit:
What I want:

A parent struct
- This struct has a few stub methods the child will get
- The parent has a static method which will also be given to the child
-> In this method it referes to another static method of thistype (the struct itself)

A child struct
- Which extends the parent
- Which has a few new methods (stub overwrite)
- Which has a few parent methods (like the static one, without needing to rewrite in child)
08-27-2009, 06:59 PM#2
Anitarf
Because that's not what thistype was made for and it's not how it works.

It was designed specifically for modules and textmacros and is basically just a placeholder for the struct's real type. In your example, it gets replaced with A by the preprocessor. I'm not sure why the thing even compiles since test2 is not a static method.

Have you tried simply using call .test2()?
08-27-2009, 07:22 PM#3
Anachron
Oh, it is a static method, I just need to know how I can call the method of a child in the child itself with having the method of the parent used.
08-27-2009, 07:56 PM#4
Rising_Dusk
Moved to the triggers and scripts forum.
08-28-2009, 07:11 AM#5
Anachron
Anyone know how I can do this?

Edit:
Any why is thistype not everywhere thistype, but the type of the parent?
Why isn't it saved in another variable, like parenttype?

Doesn't make sense.
08-28-2009, 12:59 PM#6
Anitarf
Quote:
Originally Posted by Anachron
Anyone know how I can do this?

Edit:
Any why is thistype not everywhere thistype, but the type of the parent?
Why isn't it saved in another variable, like parenttype?

Doesn't make sense.
Again, it's because that's not what thistype was designed for.
I'm not even sure you can have stub static methods. Try making it a regular method?