interface question

Viikuna

No Marlo no game.
Reaction score
265
This works. It prints "A"

JASS:
scope noob initializer Init

interface face
    string lol
endinterface

struct A extends face
   string lol = "A"
endstruct

function Actions takes nothing returns nothing
    local A a=A.create()
    call BJDebugMsg(a.lol)
    call a.destroy()
endfunction


This too works. It prints "A", "B" and "C"

JASS:
scope noob2 initializer Init

private interface face
    method lol takes nothing returns nothing defaults nothing
endinterface

private struct A extends face
   method lol takes nothing returns nothing 
       call BJDebugMsg("A")
   endmethod
endstruct

private struct B extends A
  method lol takes nothing returns nothing 
       call BJDebugMsg("B")
   endmethod
endstruct

private struct C extends B
    method lol takes nothing returns nothing 
       call BJDebugMsg("C")
   endmethod
endstruct

private function Actions takes nothing returns nothing
    local A a=A.create()
    local B b=B.create()
    local C c=C.create()
    call a.lol()
    call b.lol()
    call c.lol()
    call a.destroy()
    call b.destroy()
    call c.destroy()
endfunction

endscope


But this one does not. it says: Member already in use by a parent type.

JASS:
scope noob3 initializer Init

private interface face
    string lol
endinterface

private struct A extends face
   string lol = "A"
endstruct

private struct B extends A
  string lol = "B" // I cant redeclare lol here
endstruct

private struct C extends B
    string lol = "C" 
endstruct

private function Actions takes nothing returns nothing
    local A a=A.create()
    local B b=B.create()
    local C c=C.create()
    call BJDebugMsg(a.lol)
    call BJDebugMsg(b.lol)  
    call BJDebugMsg(c.lol)
    call a.destroy()
    call b.destroy()
    call c.destroy()
endfunction

endscope


So, how should I actually use interface variables with structs which extend eachother? Should I just use methods because they seem to be working, or is there some other way?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
JASS:
scope noob3 initializer Actions

private interface face
    string lol
endinterface

private struct A extends face
   //ofc redeclare lol here is a code error
endstruct

private struct B extends A
  string lol = "B"
endstruct

private struct C extends B
    string lol = "C" 
endstruct

private function Actions takes nothing returns nothing
    local A a=A.create()
    local B b=B.create()
    local C c=C.create()
    set a.lol = "A"
    call BJDebugMsg(a.lol)
    call BJDebugMsg(b.lol)  
    call BJDebugMsg(c.lol)
    call a.destroy()
    call b.destroy()
    call c.destroy()
endfunction

endscope


Because struct A extends the interface , it has already the string member lol, that's the point of an interface, duhh.
 

saw792

Is known to say things. That is all.
Reaction score
280
No, you can override the interface's members I believe. You cannot override the members of a struct that you extend another struct from, however.

EDIT: It's not overriding the interface members, I checked the manual. An interface requires structs that extends it to have the same members/methods, although more can be added of course. Extending a struct does not have this requirement, and as you found causes a syntax error.
 

Viikuna

No Marlo no game.
Reaction score
265
Yea ofcourse. Sometimes my own stupidy amazes me. lol :D

Child struct has all parent structs members so I dont have to redeclare those members. Those interfaces just confused me so I forgot it.

Anyways thanks for help. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top