HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Extending Interfaces and Structs

03-28-2010, 05:03 PM#1
Wizardum
I'm having a problem trying extending an interface in a struct.

Expand Code1:

when I check if the method exists (a method from the interface), it always returns false.

Expand Code2:

so basically if I want to extend a struct from the dmMotion struct and have a method called onMotion it won't work, since the dmMotion itself is the one that's calling that method if it exists.

vJass alternative


Collapse JASS:
private interface MotionEvents
   method onMotion takes nothing returns nothing defaults nothing
endinterface

struct dmMotion extends MotionEvents

Collapse JASS:
if m.onMotion.exists then
   call BJDebugMsg( "It Should work" )
   call m.onMotion( )
endif



so now I ask if there is some lost functionality in Zinc regarding interfaces, or is this a bug or if it's something I did wrong here.

I also noticed that stub methods aren't available in Zinc, what a shame..

I'll post here the whole code
Expand Library:
03-28-2010, 11:17 PM#2
TheKid
I don't understand your interface declaration, can you declare methods like that?

In vJass its:

Collapse JASS:
interface someinterface
    method onEvent takes nothing returns nothing defaults nothing
endinterface

struct somestruct extends interface
    ...
    call .onEvent()
endstruct

Looking through the Zinc Manual, I came across this example for interfaces:

Collapse Zinc:
        interface F
        {
            method balls(integer x) = null; //this method 'defaults nothing'
            method bells(integer y) -> real = 0.0 ; //this method defaults a 0.0 for the real return

            //a static create method for the interface
            static method create();
        }

So I guess you were declaring it properly. I don't know why its all highlighted in red though this is just a copy+paste.
03-28-2010, 11:45 PM#3
Kueken
I came across this, too. Its most likely a functionality loss for zinc (there are actually many, you cannot use hook in zinc blocks, static ifs do not work outside of functions like they seem to do in vJass etc... many small things)
03-29-2010, 02:24 AM#4
Fledermaus
@ TheKid: use [zinc] tags

Collapse Zinc:
        interface F
        {
            method balls(integer x) = null; //this method 'defaults nothing'
            method bells(integer y) -> real = 0.0 ; //this method defaults a 0.0 for the real return

            //a static create method for the interface
            static method create();
        }
03-29-2010, 04:02 AM#5
TheKid
There we go.
03-29-2010, 12:32 PM#6
Wizardum
Quote:
Originally Posted by Kueken
I came across this, too. Its most likely a functionality loss for zinc (there are actually many, you cannot use hook in zinc blocks, static ifs do not work outside of functions like they seem to do in vJass etc... many small things)

oh I didn't know static ifs could be used outside functions, but well I only discovered them in Zinc.

When this problem occurred to me, I tried to do a workaround with stub methods, they didn't work, because Zinc doesn't support them. -.-'

Damn it, Zinc is so much faster to write, I was getting used to it, but the lack of functionality makes me rethink on what language should I turn to.

Edit:

I've been all morning converting most of my scripts into vJass, hell of a boring work.

But what the hell?? it still doesn't work.

My eyes are hurting right now, I didn't find any bug in the script though.
So please can someone take a look?
I'd be really appreciated

Expand JASS:
03-29-2010, 03:59 PM#7
TheKid
Collapse JASS:
                if ( m.onMotion.exists ) then
                    call BJDebugMsg( "It Should Work" )
                    call m.onMotion( )
                endif

I'm assuming this is the lines you're referring to?

Try declaring the method inside the child-struct, perhaps .exists only works on methods that are not virtual, in other words they are actually declared in the struct of which they are used.

There really is no point in having if (method.exists) then because the struct extends an interface that has the method, meaning the child structure will always have that method.
03-29-2010, 04:05 PM#8
Kueken
Not always, look at how xecollider is coded, it extends an interface holding the loopControl and onUnitHit methods. These are only called in xecollider's periodic function, if they exist in the final (user-created) struct extending xecollider. So using loopControl and onUnitHit is optional, similar to this onMotion method.

€ I cannot see any difference to xecolliders code atm, but for xecollider, it works as intended.

Essential part:
Expand JASS:

€€ Oh well, it seems to work in Zinc for me:
this
Expand Zinc:
works.
Note, that you cannot call go in the create method, because go.exists returns false there.
But after the creation finished, go.exists returns true correctly (at least for me :P), thats why I call a 2nd function, callGo.

Well, but it is actually not different to your own library code, which does not work o_0
03-29-2010, 05:46 PM#9
TheKid
Unless perhaps "m" is a null struct (0) or something. I tried it out in my own code too (vJass) and it worked. Do you have the latest version of JassHelper?
03-29-2010, 07:41 PM#10
Wizardum
Quote:
Originally Posted by Kueken
Not always, look at how xecollider is coded, it extends an interface holding the loopControl and onUnitHit methods. These are only called in xecollider's periodic function, if they exist in the final (user-created) struct extending xecollider. So using loopControl and onUnitHit is optional, similar to this onMotion method.

€ I cannot see any difference to xecolliders code atm, but for xecollider, it works as intended.

Essential part:
Expand JASS:

€€ Oh well, it seems to work in Zinc for me:
this
Expand Zinc:

works.
Note, that you cannot call go in the create method, because go.exists returns false there.
But after the creation finished, go.exists returns true correctly (at least for me :P), thats why I call a 2nd function, callGo.

Well, but it is actually not different to your own library code, which does not work o_0

Yes you'll find a lot of things in my code similar to xe, because as I'm working on this, I'm actually learning from xe.

but anyway, I didn't call the method from the create method, at least I don't think I did that.

Quote:
Originally Posted by TheKid
Unless perhaps "m" is a null struct (0) or something. I tried it out in my own code too (vJass) and it worked. Do you have the latest version of JassHelper?
I think I do, at least I had to reinstall JNGP today and I updated the jasshelper.

Anyway I'll post here the map for anyone to test.
If this indeed work on your JNGP, then I'd like that someone of you to attach here your JNGP folder so I can have it.
Attached Files
File type: w3xSystem Map.w3x (250.9 KB)
03-30-2010, 12:09 AM#11
Wizardum
Problem Solved!

The issue was in this part:

Expand Zinc:

this would make possible the creation of the missile and everything, except for the interface's method, somehow, yet to be discovered.

I simply solved by doing this:
Expand Zinc:

It's now working perfectly!
Thanks for all the help guys, cookies are going to be distributed among everyone ^^