PDA

View Full Version : data_common.lua



Varsuuk
June 21st, 2018, 06:58
What guides the choice of putting things in one place or another.

For 5E, there are many maps/arrays defined "globally" outside of a function. This is followed by an "onInit()" method where other maps are defined but one thing they all have in common is a call to "Interface.getString("XXXX")" - Not sure why they would be separated as not sure when "onInit()" would be called for a file vs control "scope"?

For the AD&D Core, Celestian adds variables empty declares outside of onInit() then onInit() populates the maps vs trying to declare nested maps in one "=" assignment? Is that the only reason to have the empty declare then onInit() splitup?

Just hit adding my own data lookups and wanted to know how to design what goes where :)

Trenloe
June 21st, 2018, 07:40
Quick answer - Interface.getString is used to allow translation of the GUI. Allowing just the string XML files to be changed to translate the GUI to a different language.

Varsuuk
June 21st, 2018, 13:27
Yup, I use that everywhere. When I started in the business I used to work on a client GUI app for Pager/Cellular Carriers (Notify!) and I had set it up for easy (... well debugging the Traditional Chinese one was really rough, Portuguese was not as bad) translation using string resources in Visual C++.

My question was why is some of the code in that file in the onInit() method and the rest not. Not sure why the onInit() was needed in DataCommon.lua. Not >challenging< this - I really am just unexperienced to know and I am creating my own such file so I want to know rule of thumb and rationale for putting in "global scope" or "function scope (of a global vs control script)"

The only thing I saw to distinguish in 5E one was that all in onInit() called Interface.getString() - that was the common part of every assignment in onInit(). In AD&DCore - no such commonality existed.

So was looking for insight.

Trenloe
June 21st, 2018, 15:06
The only thing I saw to distinguish in 5E one was that all in onInit() called Interface.getString() - that was the common part of every assignment in onInit(). In AD&DCore - no such commonality existed.
I'm not sure what you're saying here - in data_common.lua in both 5E and AD&D Core the Interface.getString API function is only used in the onInit function, not outside of it.


My question was why is some of the code in that file in the onInit() method and the rest not. Not sure why the onInit() was needed in DataCommon.lua.
I haven't tested it, but I'm guessing that Interface.getString will only work as part of code that runs, not a static LUA table record definition (outside of onInit).

There is only the need for Interface.getString within the LUA table records defined in data_common.lua if there is data that might need to be translated. Looking at 5E, this is: class names, skill names, party sheet ability and skill drop-down names.

Varsuuk
June 21st, 2018, 22:32
The needing to be once “loaded” (I’m not hep to terminology) via onInit() for the Interface is what I guessed from that being the common thread to ALL the lines in 5e’s onInit().

If that was the only thing I looked at, I’d assume that and walk away.

Was then wondering in AD&D, he has a variety of array assignments in onInit(). Now that first part seems verified, why were these put in onInit(). Random/style choice or also, like Interface, needs to have something “loaded” before it was valid to assign these? So, I get Interface - why in AD&D are other things there?


But I guess that’s likely only something Celestian will easily answer if he sees this. He IS a busy (super) bee hard at work making yumminess ;)

Andraax
June 22nd, 2018, 03:21
Because he needed them initialized at the beginning of a session...

Trenloe
June 22nd, 2018, 03:50
Was then wondering in AD&D, he has a variety of array assignments in onInit(). Now that first part seems verified, why were these put in onInit(). Random/style choice or also, like Interface, needs to have something “loaded” before it was valid to assign these? So, I get Interface - why in AD&D are other things there?
If you look closely at the entries that don't have getString commands in onInit in the AD&D ruleset - these are all setting a LUA table record to be blank - where in 5E these all had getString assignments - the 5E code remains in the LUA file, but is commented out.

This empty LUA table doesn't have to be here (in onInit), it could be in the main section of the LUA script (outside of onInit). But, it makes more sense to put the code right by the commented out code - so that when people look at this they see the commented out code and the new blank table. In theory, reducing confusion and random questions! ;-)

It's purely ascetics and a decision celestian made in the code. Don't try to over analyze it!

Varsuuk
June 22nd, 2018, 04:39
Thanks :)

Yeah, I know - I overanalyze things.
But in 7 years, no outages on a Financial Exchange Server I code (last 5, solo) and maintain *knocks on head*

I like to understand things as I pass them - I think it comes from all the old RogueSix/Battlefield 2 tourney games - I learned never to advance without clearing all corners and leave unopened doors at your back.

Troof.


But yeah, that's what I wanted to grokk - in case there was a reason - I am more feeling my way through with Lua then a qualified Lua guy ;)