Author Topic: Function Declaration  (Read 504 times)

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Function Declaration
« Reply #15 on: March 18, 2014, 09:19:45 pm »


               


I believe where people are getting confused is, Funky uses NWNTX to compile scripts, which allows him to do things which are "not normal" in the toolset....


 


If you tried to compile a script in the normal Toolset with a main in the "main script" and a main in the "include" you would indeed get an error.... (see below)


 


ERROR: DUPLICATE FUNCTION IMPLEMENTATION (main)




This only happens if you have void main in the script/includes more than once. Has nothing to do with WHERE in the script or its includes the function is.


 


Funky


               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Function Declaration
« Reply #16 on: March 18, 2014, 09:22:40 pm »


               


The way I see it, you only have to write the non-configurable stuff once, ShaDoOoW.  Many spells are structured similarly but have different data inserted into them. Nevertheless you've got nearly identical mains in each of them. If you wanted to change the way the main behaved you'd have to change it in every similar spell script. The way Higher Ground does it, you just tweak the one main in that include and every spell in that area of effect suite is updated at the same time.


 


The way I am doing things now I either tediously edit each main, or I pull all the scripts out of temp0, and run find|sed on them for a batched find/replace. Usually I just edit each one one at a time.




Exactly. It's the same reason you have a certralized spells include. When we make, for example, edits to the handling of Herald of Storm spells, we do it once, not a half dozen times. It has numerous advantages, many of which are subtle, but it boils down to this: it's simply better normalization, in terms of storage of relational storage. Likewise, for our spells include, if we want to change the handling of SR, we do it once, in ac_spells, and that impacts ALL spells once they're recompiled. It takes a lot of work to set up, but it saves a TON of work in the long run.


 


Funky


               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Function Declaration
« Reply #17 on: March 18, 2014, 09:27:21 pm »


               




Ok i see. But, you can accomplish this exact advantage without this setup by using a same spellscript for multiple spells and switch-case differences




Yeah, we do that in a lot of spells. See, e.g., hgs_gen_orb (we have a lot of hgs_gen scripts like that, that handle multiple spells each). In this case, however, it doesn't work so well - the void main, or the switch, would be a real mess, and difficult to comprehend. Take a look and you'll see. In the end, it boils down to preference. I'm not saying this is the only way to do this, just a very handy way in some situations.


 


Funky