PDA

View Full Version : Coding in <script> vs referring to script file?



Varsuuk
March 12th, 2019, 00:40
[SOLVED]

Is there any things to be aware of or particularly careful about putting Lua code in an .lua file referenced in windowclass or control's <script> block vs putting it all inline in the block?

I know you get better errors in .lua files
You can see immediately what is going on when it is inline (especially for very short methods and events)

Any other pro-cons in either direction? I figure thoughts and styles evolve over time and what FG devs prefer now might have changed from what it was when some rulesets were first coded.

Thanks guys :)

(PS - if this answer is more than trivial, perhaps it should be spelled out in the https://www.fantasygrounds.com/modguide/scripting.xcp page. The mechanics are, but unless that is it - no other things to consider, the pro/cons are not compared.)

celestian
March 12th, 2019, 00:52
If it's a small snippet of code using <script> will be ok. Just be aware that any character that causes problems with xml will cause problems there. Such as <>~ and so on. This includes stuff like if nCount > nSize then....

Moon Wizard
March 12th, 2019, 01:05
That’s how I use as well. If it’s only a handful of lines used in a single spot, then I inline the script. If I re-use or it’s longer than a few functions, I usually move to script file.

Only real difference is error output and special character / comment escaping needed when inline.

Regards,
JPG

Varsuuk
March 12th, 2019, 01:50
Great thanks. I was just making sure there were no “special” features/access only usable in the xml.

I too prefer in scripts if it clutters the file / not a line or three :)


Really glad I made time for this, I am blowing off my ESO playing to get some nice relaxation time coding vs stupid work coding.

I spent two weeks on a “Warmup framework”, whoooopeee... it doesn’t even have a visible aspect, nor does it ROLL DICE - what good is it I ask?!