wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-22-2010, 06:26 AM   #1
TheKid
User
 
TheKid's Avatar
 
Join Date: Mar 2009
Posts: 195

TheKid will become famous soon enough (37)TheKid will become famous soon enough (37)

Default Optional Module Methods

What is the common method of determining whether or not a module has been implemented by an implementing struct, namely using methods that may/may not have been declared depending on whether or not the module was implemented.

I also have another question, let's say I have a struct. Let's say this struct is likely to be extended (almost like an abstract struct), though I want to also be able to use modules on the "super" struct, how likely is this to perform properly? I remember having some troubles with inheritance and module implementation, I'm not sure though - any feedback?

-------------------
Edit #1 (1:57AM)
It seems that modules implemented in the super-type work properly in structs that inherit the properties of that super-type. I remember having a problem with inheritance and AutoIndex though.
__________________

Last edited by TheKid : 07-22-2010 at 06:59 AM.
TheKid is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-22-2010, 09:56 AM   #2
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by TheKid
What is the common method of determining whether or not a module has been implemented by an implementing struct, namely using methods that may/may not have been declared depending on whether or not the module was implemented.
Collapse JASS:
            static if thistype.moduleMethod.exists then
                call .moduleMethod()
            endif

Quote:
I also have another question, let's say I have a struct. Let's say this struct is likely to be extended (almost like an abstract struct), though I want to also be able to use modules on the "super" struct, how likely is this to perform properly? I remember having some troubles with inheritance and module implementation, I'm not sure though - any feedback?

-------------------
Edit #1 (1:57AM)
It seems that modules implemented in the super-type work properly in structs that inherit the properties of that super-type. I remember having a problem with inheritance and AutoIndex though.
Modules are essentially textmacros, so any methods they implement will behave the same as if they were written in the struct manually.
__________________
Anitarf is offline   Reply With Quote
Old 07-22-2010, 10:58 AM   #3
TheKid
User
 
TheKid's Avatar
 
Join Date: Mar 2009
Posts: 195

TheKid will become famous soon enough (37)TheKid will become famous soon enough (37)

Default

I remember having problems with AutoIndex though which lead me to believe (I believe EarthFury said something about them not working smoothly together too) that they were not fully compatible. It seems like for the most part they are, perhaps I was doing something stupid which caused them to malfunction for me.

So then, the answer is a static if statement? I was using just a regular one, which would not compile.

The error it was giving me before was that "methodName is not of type that allows "." syntax."; I'm curious as to how the static if-statement bypasses this.
__________________

Last edited by TheKid : 07-22-2010 at 11:00 AM.
TheKid is offline   Reply With Quote
Old 07-22-2010, 11:31 AM   #4
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Static ifs are evaluated at compile time, if they evaluate to false the code inside them is not parsed, so you can't get an error on it. It's all in the documentation.
__________________

Last edited by Anitarf : 07-22-2010 at 11:32 AM.
Anitarf is offline   Reply With Quote
Old 07-22-2010, 12:59 PM   #5
TheKid
User
 
TheKid's Avatar
 
Join Date: Mar 2009
Posts: 195

TheKid will become famous soon enough (37)TheKid will become famous soon enough (37)

Default

Oh, I see; I don't even have to put valid values into a static if-statement - that's nice to know.

Collapse JASS:
static if THIS_IS_NOT_A_VARIABLE then
    private static string s = null
endif

This compiles perfectly fine despite THIS_IS_NOT_A_VARIABLE not even existing in any sense.
__________________
TheKid is offline   Reply With Quote
Old 07-22-2010, 01:28 PM   #6
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Yes, any non-existing value defaults to false. It is how static ifs can check for non-existent libraries in the first place. Of course, deliberately using an invalid value such as THIS_IS_NOT_A_VARIABLE kind of defeats the purpose of having an if statement in the first place.
__________________
Anitarf is offline   Reply With Quote
Old 07-22-2010, 04:05 PM   #7
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 233

Submissions (1)

Bribe will become famous soon enough (30)Bribe will become famous soon enough (30)

Send a message via AIM to Bribe
Default

Berb, something about modules ~ each module is going to have a *fixed* static-if setup, meaning that almost every static-if will be the same for each struct it is implemented in.

The only way I know of to have different static-if compile differences is to use what Anitarf said (methodname.exists). You can actually use this in a disgusting way to achieve configurable modules

Collapse JASS:
module MODULE
  static if thistype.ENABLE.exists then
    // do enabled actions
  else
    // do disabled actions
  endif
endmodule

struct test

    implement MODULE

    method ENABLE takes nothing returns nothing
    endmethod

endstruct

Last edited by Bribe : 07-22-2010 at 04:07 PM.
Bribe is offline   Reply With Quote
Old 07-22-2010, 07:44 PM   #8
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

I'm pretty sure you can use constant booleans in static ifs, no need to resort to such ugly .exists abuse.
__________________
Anitarf is offline   Reply With Quote
Old 07-22-2010, 07:59 PM   #9
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 233

Submissions (1)

Bribe will become famous soon enough (30)Bribe will become famous soon enough (30)

Send a message via AIM to Bribe
Default

In a module, a static-if that reaches for a boolean that isn't in its original library defaults false before struct implentation - the only workaround I've been able to find is methodname.exists

Last edited by Bribe : 07-22-2010 at 08:00 PM.
Bribe is offline   Reply With Quote
Old 07-24-2010, 09:11 AM   #10
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by Bribe
In a module, a static-if that reaches for a boolean that isn't in its original library defaults false before struct implentation - the only workaround I've been able to find is methodname.exists
Perhaps this was a problem with an older version of JassHelper? I just used a private static constant boolean in a struct and then implemented a module containing a static if that checked that boolean: if the boolean was true, the contents of the static if were not removed in the outputwar3map.j. The module and the struct were in different libraries if you think that's important.

Zinc documentation states that static ifs are evaluated before modules, in that case it would make sense for values in the struct not to be recognised by the static if in the module; however, if that were the case, then methodname.exists wouldn't work either. However, both methodname.exists and static constant booleans work correctly in static ifs inside modules individually for every struct that implements the module.
__________________
Anitarf is offline   Reply With Quote
Old 07-24-2010, 09:21 AM   #11
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 233

Submissions (1)

Bribe will become famous soon enough (30)Bribe will become famous soon enough (30)

Send a message via AIM to Bribe
Default

You had to use thistype. as a prefix to the constant in your module, right? I just tested it, and it didn't recognize the boolean unless I used thistype.

And it works!? It's like magic. I swear I tested this thing before with and without thistype. as a prefix and the module flatly ignored the boolean. Huh. Crazy things.

Thanks :D
Bribe is offline   Reply With Quote
Old 07-24-2010, 09:39 AM   #12
Deaod
User
 
Join Date: Jan 2007
Posts: 542

Submissions (11)

Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)

Default

Actually, Bribe, the example you showed is faulty.
static if thistype.ENABLE.exists then will always return false, unless you move the method ENABLE above the implement statement.
__________________
Deaod is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 05:16 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services