problem with interface^^

darkbeer

Beer is Good!
Reaction score
84
hey, i got a little problem concerning interfaces:

i got a struct which extends an interface, it has several methods.

now i need to change just 1 or 2 methods for every other struct, i thought i would make the second struct extend the first, but so it only calls the method of the first ( confusing i know)

example:

JASS:
interface a
    method abc takes nothing returns nothing
endinterface

struct first extends a
   method abc takes nothing returns nothing
       //actions etc... ...
   endmethod

   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("THIS IS DISPLAYED")
   endmethod
endstrut

struct second extends first
   method PROBLEM takes nothing returns nothing
       call BJDebugmsg("THIS ISNT DISPLAYED")
   endmethod
endstruct


now if i call for the problem method of struct second it will always execute the one of first.

but i need the abc method to be the same??

any suggestion (hope u get what i mean :p)
 

Builder Bob

Live free or don't
Reaction score
249
You're right, it's confusing. I don't get what you mean.

Maybe you want to use a method that by default returns a specific value (like nothing), but that you can specify in extended structs?

JASS:
interface a
	method abc takes nothing returns nothing defaults nothing
endinterface

struct first extends a
	
	method abc takes nothing returns nothing
		//actions etc... ...
	endmethod
	
	method PROBLEM takes nothing returns nothing
		call BJDebugMsg("THIS IS DISPLAYED")
	endmethod
	
endstruct

struct second extends first
	
	//this special abc method will be used for struct second
	method abc takes nothing returns nothing
		//actions etc... ...
	endmethod
	
	//Member name already in use by a parent type, so I commented out this method
	//method PROBLEM takes nothing returns nothing
	//	call BJDebugMsg("THIS ISNT DISPLAYED")
	//endmethod
	
endstruct

struct anotherOne extends first
	//abc method for struct first will be used when no abc method is specified
	
endstruct
 

duyen

New Member
Reaction score
214
hey, i got a little problem concerning interfaces:

i got a struct which extends an interface, it has several methods.

now i need to change just 1 or 2 methods for every other struct, i thought i would make the second struct extend the first, but so it only calls the method of the first ( confusing i know)

example:

JASS:
interface a
    method abc takes nothing returns nothing
endinterface

struct first extends a
   method abc takes nothing returns nothing
       //actions etc... ...
   endmethod

   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("THIS IS DISPLAYED")
   endmethod
endstrut

struct second extends first
   method PROBLEM takes nothing returns nothing
       call BJDebugmsg("THIS ISNT DISPLAYED")
   endmethod
endstruct


now if i call for the problem method of struct second it will always execute the one of first.

but i need the abc method to be the same??

any suggestion (hope u get what i mean :p)

The problem is that you did 'endstrut' instead of 'endstruct'.

Fixed:
JASS:
interface a
    method abc takes nothing returns nothing
endinterface

struct first extends a
   method abc takes nothing returns nothing
       //actions etc... ...
   endmethod

   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("THIS IS DISPLAYED")
   endmethod
endstruct

struct second extends first
   method PROBLEM takes nothing returns nothing
       call BJDebugmsg("THIS ISNT DISPLAYED")
   endmethod
endstruct
 

XeNiM666

I lurk for pizza
Reaction score
138
i believe JASS is case-sensetive?

JASS:
call BJDebugmsg("THIS ISNT DISPLAYED")

sould be
JASS:
call BJDebugMsg("THIS ISNT DISPLAYED")
 

Expelliarmus

Where to change the sig?
Reaction score
48
@Anman64
- enstruct error should display during compilation.
- "THIS IS DISPLAYED" clearly showed.
- Thus it is most likely this was an edited version of a full code, with a small error.
=D I might be wrong though ^_^
 
Reaction score
333
As far as I know methods aren't supposed to be virtual like that. In fact that code did not even compile for me, even with the other errors fixed. Here is code that does work:

JASS:
interface a
    method abc takes nothing returns nothing
    method PROBLEM takes nothing returns nothing
endinterface

struct first extends a
   method abc takes nothing returns nothing
       //actions etc... ...
   endmethod

   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("THIS IS DISPLAYED")
   endmethod
endstruct

struct second extends first
   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("THIS ISNT DISPLAYED")
   endmethod
endstruct
 

Artificial

Without Intelligence
Reaction score
326
You could use the new delegate thingy, too. ^_^

JASS:
interface a
    method abc takes nothing returns nothing
endinterface

struct first extends a
   method abc takes nothing returns nothing
       //actions etc... ...
       call BJDebugMsg("abc")
   endmethod

   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("1st")
   endmethod
endstruct

struct second
   delegate first somename
   method PROBLEM takes nothing returns nothing
       call BJDebugMsg("2nd")
   endmethod
endstruct

scope test initializer i

function i takes nothing returns nothing
    local second s = second.create()
    local first f = first.create()
                     // DISPLAY:
    call f.PROBLEM() // 1st
    call f.abc()     // abc
    call s.PROBLEM() // 2nd
    call s.abc()     // abc
endfunction

endscope
You're need JassHelper 0.9.D.0 or later, though (get the newest one from here).

The delegate means that when something is called for an instance of second (or a static member of second is called) and it's not found in the second struct itself, JassHelper will search for that member from the delegates of the struct. If it's found from any of those, that one will be used. At least IIRC. :p
 

darkbeer

Beer is Good!
Reaction score
84
PERFECT!

thx very much artifical^^ works flawlessly

and to the others ye i just made that out of my hea, thats why there were all the compiling errors^^ thx to all of you
 
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