| 07-26-2014, 01:30 PM | #1 |
this is gonna be a multi-parter, all help is much appreciated if you can only answer some! in the vJASS help doc, Vex says that globals should not reference other globals in declarations part 1. is does this apply to constants? (these examples are imagined as separate triggers) A:globals constant integer MaxNumberPlayers = 8 endglobals B:globals unit array Heroes[MaxNumberPlayers] endglobals part 2. does this apply if they're manually ordered using libraries? A:library A globals integer x = 5 endglobals endlibrary B:library B requires A globals //i realize y would only capture x's initial value... //handles (being sorta pointers) would have updated data visible to both globals... I think? integer y = x endglobals endlibrary q2: if nothing requires library A, do these do the exact same thing (in different ways) Version 1:library A initializer initA globals unit array heroes[4] endglobals function initA takes nothing returns nothing set heroes[0] = ... ... endfunction endlibrary Version 2:globals unit array heroes[4] endglobals function InitTrig_A takes nothing returns nothing set heroes[0] = ... ... endfunction minor differences in this last section are important, especially each's limitations |
| 07-26-2014, 04:20 PM | #2 |
Referencing other library globals should not be a problem if you properly build an "order tree" via requires/needs/uses. If you do not, however, it might easily output error because object/scalar we are trying to referece to, is not yet defined. And yes, this would use only initial values. If you want to make sure that parent's lib data is initialized especially when part of it can not be initialized directly within globals block use module initializer. If you don't, it might happen that child struct with module initializer "extending" parent struct from another library may have it's data initialized prior to parent struct, thus providing false results. Here (under "Initialization Priorities") you can find the proper order of all posible inits. |
| 07-27-2014, 12:56 PM | #3 |
Thanks for the help, Inferno Ok cool -- I didn't think it would pull the globals into the script header AND remember where it pulled them from :) and ah that's a good guide, wish I had that when I was planning organization... so the only difference is in which resolves first? is using cohadar's flavor of JASS the new standard? |
| 07-27-2014, 07:19 PM | #4 | |
Inferno hit the nail on the head. I just thought I'd jump in and mention that this: JASS:globals unit array heroes[4] endglobals You might've just been giving examples, but I figured I'd let you know. Quote:
Cohadar's jasshelper fixes the initialization order. It would be considered "standard", but it has some random bugs, according to Nestharus. I use it sometimes, but there are some annoying parts of it (e.g. the //! external warning). If you download moyack's JNGP 2.0, you can switch between vex's and cohadar's jasshelper really easily through the jasshelper menu. Anyway, it is a good habit to make use of libraries and its "requires" keyword. In fact, a lot of people ditch using scopes at all and just stick with libraries. |
| 07-28-2014, 06:29 PM | #5 |
I'd second Purge's suggestion of only using libraries, it's better to always explicitly write down the requirements of your code. In fact, when Vexorian wrote Zinc, he made it only use libraries. |
| 07-31-2014, 05:56 AM | #6 | |||
Quote:
i haven't tried switching since it's only guaranteed to be compatible in one direction (going to cohadars) Quote:
Quote:
thanks again for the info |
