HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Tutorial on struct extensions, interfaces

07-11-2008, 06:19 PM#1
the-thingy
I'm reading a tutorial on method interfaces (link), but I find alot of it very confusing. Is there a simpler tutorial on methods/interfaces around? I looked at the tutorials section, and very little related to structs (and nothing related to methods)

The thing that really confuses me is referring to struct members when using parent structs with the interface and children struct e.g. (alot of this is based on what I kind of understand from the tutorial, but I could be very very wrong)

Collapse JASS:
interface AllThings
method MoveThing takes nothing returns nothing
endinterface

struct ThingMethods extends AllThings
//Does this need to have any particular members?

method MoveThing takes nothing returns nothing
call SetUnitX (...) //How do I refer to the struct member from a child struct?
call SetUnitY (...)
endmethod
endstruct

struct Box extends ThingMethods
unit whichThing
real size
real weight
real movedist
//Bla bla bla, some more members
endstruct

struct Ball extends ThingMethods
unit whichThing
real size
real weight
real movedist
endstruct

function MoveObject takes AllThings a returns nothing
call a.MoveThing ()
endfunction

function TestFunc takes nothing returns nothing
local Ball data = Ball.create ()
set data.whichThing = CreateUnit (...)
//A few random values here and there
set data.size = 1
set data.weight = 2
set data.movedist = 7
call MoveObject (data)
endfunction

I did read through the stuff on interfaces in the JassHelper manual, but that only explains
Interface -> Struct A, B, C

as opposed to
Interface -> Parent Struct -> Child Struct A, B, C
07-11-2008, 06:39 PM#2
Flame_Phoenix
Well, to learn vJASS i recommend this two links:
- http://www.hiveworkshop.com/forums/f...chnique-59259/
- http://wc3campaigns.net/vexorian/jas...anual.html#lib

Hope it helps =)
07-11-2008, 06:46 PM#3
the-thingy
Quote:
Originally Posted by Flame_Phoenix
Well, to learn vJASS i recommend this two links:
- http://www.hiveworkshop.com/forums/f...chnique-59259/
- http://wc3campaigns.net/vexorian/jas...anual.html#lib

Hope it helps =)
I know vJASS (fairly well), I just want to learn about struct extensions and method interfaces because, of all the vJASS features I've come across so far, they are the most confusing.

I kind of understand the interface -> struct a, b, c thing, but the interface -> parent struct -> children struct confuses me, especially when trying to refer to the struct members in the method (like in the code I wrote, assuming it's legible :P)
07-11-2008, 06:51 PM#4
moyack
I did this tutorial about doing spells with structs, check my signature to see it. (link)

Interfaces are more suitable for systems (in other words not often used), but the best documentation so far is the JassHelper manual.
07-11-2008, 06:51 PM#5
Flame_Phoenix
My second link explains what Interfaces are. You should give it a try.
07-11-2008, 06:53 PM#6
the-thingy
Quote:
Originally Posted by Flame_Phoenix
My second link explains what Interfaces are. You should give it a try.
I did read it!!!

Quote:
I did read through the stuff on interfaces in the JassHelper manual, but that only explains
Interface -> Struct A, B, C

as opposed to
Interface -> Parent Struct -> Child Struct A, B, C

And I don't see anything about extending structs to interfaces/each other

EDIT: Damn, I must be blind... never saw the "Extending Structs" part of the JassHelper index, but it still doesn't fully explain if/how I can reference members from the child structs in the parent struct (since the example takes a unit argument, but from my understanding of the tutorial I linked to, I don't need an argument for the method)
07-11-2008, 07:38 PM#7
moyack
One question: Why do you need to extend a struct?? are you doing a system???
07-11-2008, 07:43 PM#8
the-thingy
Quote:
Originally Posted by moyack
One question: Why do you need to extend a struct?? are you doing a system???
Primarily for learning purposes (so, whenever I might need it, I'll know how) and for generally messing around with various things in WE (I like to know how stuff works so I can play around with it )
07-11-2008, 08:01 PM#9
moyack
I see, well, For spell making knowing libraries, scopes and structs is more than enough.

When you do a system, probably, you could need the extend and the interfaces commands. When you extend a struct is because you're creating new struct which shares parts of other struct (BTW, child structs can get info from the parent, but not the opposite)

Interface is used commnly to convert a function into an object, so we can use the function.execute() with arguments.

One suggestion taht I have in order to learn the practical usage (and avoid any biased conception, including mine :P) is to check systems, one that uses it a lot is the SSE engine system. I don't have the link at hand, but you can find it in the systems resouce.

EDIT: Ok, added the link.
07-11-2008, 08:06 PM#10
Vexorian
My tasks queue includes making a tutorial about this cause I am a little mad at everyone seeing them as ultra hard things to use. Yes, I am talking about Dusk here.

For now, do you have a question as yo what's confusing about them? There's a sample in jasshelper_path\demos btw.

Ah, the answer to the question you made is: You can't access the parent's member, but we will be able to do that later when/if I update jasshelper.
Edit: Perhaps I missunderstood the question? Did you try call data.MoveThing() ?

Quote:
Interface is used commnly to convert a function into an object, so we can use the function.execute() with arguments.
That's a function interface.
07-11-2008, 08:10 PM#11
the-thingy
My understanding of the usage of interfaces is:

For dealing with a number of similar objects/properties e.g. various shapes like cube, sphere, cone, and controlling various things relating to those objects/properties like how fast they should move when pushed, how fast they should fall, and stuff like that, without having the same methods repeated in every struct.

Would that be one way of using interfaces???

Quote:
There's a sample in jasshelper_path\demos btw.
Thanks, I'll take a look

Quote:
You can't access the parent's member
I mean:
If I called a method with a child struct e.g.
Collapse JASS:
interface MyInterface
method ParentStructMethod takes nothing returns nothing
endinterface

struct ParentStruct extends MyInterface
method ParentStructMethod takes nothing returns nothing
call BJDebugMsg (...) //How can I refer to the members of the ChildStruct instance I declared before calling this method?
e.g. I want to display myString + I2S (myInt) + R2S (myReal), but I don't have a clue how to refer to them :(
endmethod
endstruct

struct ChildStruct extends ParentStruct
integer myInt
real myReal
string myString
endstruct

function SomeFunction takes nothing returns nothing
local ChildStruct data = ChildStruct.create ()
set data.myInt = 1
set data.myReal = 2.5
set data.myString = "hello"
call data.ParentStructMethod
endfunction

How would I be able to refer to ChildStruct's members within that method
07-11-2008, 08:37 PM#12
Vexorian
You can't.

Well, you can... but you would have to know in advance it is an instance of the ChildStruct.

Collapse JASS:
struct ParentStruct extends MyInterface
method ParentStructMethod takes nothing returns nothing
    if(this.getTypeId()==ChildStruct.typeid) then
        call BJDebugMsg ( ChildStruct(this).myString )
    endif
endstruct

But this is not really what interfaces are for.
07-11-2008, 09:39 PM#13
Here-b-Trollz
weaaddar did some cool interface thing with itemMenus... I'll see if I can't dig it up.

Link: itemMenu

EDIT2: On second thought... this *might* not be the best way to learn interfaces. But it is how I learned.
07-12-2008, 12:16 AM#14
Vexorian
Mind me telling you to take a look at This some stuff is a little outdated, I could have a parent struct with its create method instead of that textmacro, but it still works fine. It shows the sort of thing interfaces are great for. A way to graduate as interface user (one of many) would be to try making a new level in snow and hazards (it is not "protected"), you'll see that making your own thing that wanders and rotates and shoots missiles is a lot like putting lego blocks together, all thanks to interfaces.