PDA

View Full Version : Function visiblity and data



Xarxus
July 8th, 2021, 10:02
Hello everyone.
After a break due to work, I resumed experimenting and studying FGU. I have two questions to you who
are much more experienced than I am.

Question 1
I found a way to override a function, which is to regenerate it with the same name and use super. to
recall the old version without having to completely rewrite it. This way I can afford to add my own
code while continuing to keep the function updated if CoreRPG (for example) updates it.


function A()
super.A();
... my code
end

The operation should correspond to that shown in the figure below
(blue -> old version - yellow -> new version).
48106

The problem I have, however, arises when the old version of Func A calls Func B. In this case the behavior
it seems to me corresponds to this.
48107

I would like this instead.
48108

Do you think is there a way to get it? The only solution I find is to completely overwrite ()copy) the
old function without calling it, and I don't like it.


Question 2
The ruleset I'm trying to experiment on is full of data. I have inserted all data in special LUAs with
functions to extract the info I need. But what if I also want to create a manual? Should I replicate
the data in the relative XML or can I use a data extraction function (perhaps automatically generating
a table, if I need it)?

Trenloe
July 8th, 2021, 10:55
Question 1: It all depends on how the old version of Function A calls Function B. If it calls it via a global script name <GlobalScript>.<function name> then you can override the function in the global script package. If it calls it within it's own scope, then there's not much you can do - other than replicating similar code in your new function A.

Question 2: It's best to put data in a module. Things like tables and other records that are accessed by users are best created in a module, not generated from LUA in a ruleset. You'll need to create a module for your reference manual and it's also recommended to put other usable data records in a module.

Xarxus
July 8th, 2021, 11:14
Tnx for your answers.

Question 1: function B is called in the middle of old function A. Take utility\scrips\ponter_selection_v4.lua. In this file you'll find updateColors function.
As you can see some other function call it, so if I write a new version of updateColors i can add my code and call older version, but onInit() will still call
the older version.
I think the only solution is to replicate the file... I'm not happy. Each new version force me to verify and replicate it again, if needed.

Question 2: so my idea to throw all data in LUAs is an error? Good (not so much :cry:) to know.
Ok, I'll have to migrate in XML :D

Trenloe
July 8th, 2021, 11:49
I think the only solution is to replicate the file...
Yep.


Question 2: so my idea to throw all data in LUAs is an error?
If you're building records that populate in the sidebar buttons, yes that's not a good idea.

Xarxus
July 8th, 2021, 14:00
Nope, I was defining LUA tables for races, classes and so on. So, I think is better to translate them in XML.

Ty 4 all