• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] call init()

Status
Not open for further replies.
Level 19
Joined
Mar 18, 2012
Messages
1,716
Simple question, is there a difference between

JASS:
        private static method init takes nothing returns nothing
            call table.create()
        endmethod

        private static method onInit takes nothing returns nothing
            call init()
        endmethod
and
JASS:
        private static method onInit takes nothing returns nothing
            call table.create()
        endmethod

I ask because I've seen this
JASS:
module OnInit
    private static method onInit takes nothing returns nothing
        call init()
    endmethod
endmodule
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
the difference is that the first has higher chance of hitting OP limit than the second one because even function call increases OP value by a bit

other than that, not really, maybe for readability, but I personally usually do the second one, unless Im running some heavy code, in which case I would just make several triggers and attach those functions to them and evaluate them all
 
It is because of the order of intiailizers.

Module initializers are executed before struct initializers. For the full order, see:
http://www.hiveworkshop.com/forums/...80/jpag-jass-proper-application-guide-204383/

Now, why is this an issue? Basically, for systems you want to ensure that your initialization is occurred at the proper time to avoid any possible errors.

Let's say you have a system that uses a library initializer to set up all the variables and junk. Now let's say you want to branch off and make a different system that uses it. If you use the first system in your new system's initializer, you have to make sure that the first system's initializer runs first. Thus, you wouldn't be able to use a struct initializer--it runs before the library initializer.

tl;dr people use module onInit methods so that it won't limit other systems using it. The reason why people use call init() inside them is so that they don't have to write the entire initialization code in a module. It just looks ugly.

As for your first two scripts, there isn't really a difference in that case. I haven't seen anyone do that--it is a waste of a function call. In this post, I'm only referring to the initialization that is placed in the module.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Cohadar's jasshelper handle initializers in a sane way, but i don't know if it's bugged though.

It is buggy, yes.

Rarely bugs, but when it does, you have to move over to vex because it doesn't support your code.

Otherwise as Purge said, the call init() within the module is for readability and less code. You don't want a bajillion on init modules, trust me ^)^. That's how we used to do it, but someone (won't name names, but it was a guy called nestharus) came up with the idea of just calling an init function within the onInit module to take initialization code outside of the modules and put it into their respective structs.
 
Status
Not open for further replies.
Top