PDA

View Full Version : Need help adding a TextWidget into CoreRPG



Jacklifear
August 23rd, 2015, 17:15
Hey everyone,

I'm working on implementing Steps from the Earthdawn Ruleset into CoreRPG and I'm having some difficulties. I keep getting some errors of items that seem to be global objects, but have a few things I need to learn about the error messages.

1. "Attempt to call global 'addTextWidget' (a nil value)

- Does this mean that it's recognizing addTextWidget as a function but it's not being defined clearly? Or is this a case that I don't have a Package installed that I should?

2. attempt to index global 'valuefield' (a nil value)

- Same style of question as above.

--------------------------------

I know these are fundamental questions, I've been diving in a few days so far and have gotten some of the basics done that I'm looking to do elsewhere, but when I start trying to get major progress on integrating the code from Steps into this, I run into a few snags and my google searches provide some minimal understanding of these. Just a nudge to the right documents would be amazing, I'd rather learn how to fish, ya know?

damned
August 23rd, 2015, 23:39
Hi Jacklifear have a look at the MoreCore extension - it is reasonably well commented. It extends CoreRPG in a couple of areas including the Character Sheets. It might help you work out your issue.
https://www.fg-con.com/morecore-extension/
https://www.fantasygrounds.com/forums/showthread.php?23281-More-Core-extension-for-CoreRPG

Trenloe
August 24th, 2015, 00:41
1. "Attempt to call global 'addTextWidget' (a nil value)

- Does this mean that it's recognizing addTextWidget as a function but it's not being defined clearly? Or is this a case that I don't have a Package installed that I should?
You're right - LAU is trying to call addTextWidget as a function but can't fine it. Assuming you're trying to call addTextWidget (https://www.fantasygrounds.com/refdoc/widgetcontainer.xcp#addTextWidget) then this code usually needs to be called as <widgetcontainer>.addTextWidget (unless this code is attached to a widget container itself) - you need to have a widget container already created and then use <widgetcontainer>.addTextWidget where <widgetconatiner is the reference to the widget container object.



2. attempt to index global 'valuefield' (a nil value)
It means your code is written in such a way that 'valuefield' is being referenced as a variable and it doesn't exist at this section of the LUA code. Make sure it's already defined/used. A common error is also that it is declared using local valuefield = 10 (for example - to make it a local variable) and then the variable is accessed in the code where the variable no longer has scope. Script scope can be based off nesting within a LUA function too - i.e. if you declare a local variable within a structured block of LUA code (e.g. if -- then) then you can't access that local variable outside of the structured block of LUA code - even if it is within the same function.

Jacklifear
August 24th, 2015, 12:12
Thanks to both of you. I downloaded and have been scouring my code. Fixed a lot of transitions and such and am learning quite well because of it

Trenloe, you are a saivor, the explanation in the first part helped me identify how to resolve that issue. Very clean and simple explanation.

Regarding the valuefield, I'm utterly stumped. I'm pulling information from one ruleset into another, All of the other functions work fine, but I still get this error regarding Valuefield. (Attempt to index global)

Here is the code:


function onInit()
valuefield = valuefield[1];
Step = 0;
source = DB.getChild(valuefield);
source.onUpdate = update;
update();
end


The error is specifically regarding the line: valuefield = valuefield[1];
Is there a problem of setting an array directly like this? I've tried setting it as a local, and it still gives an error. Without this line (even with the error) everything breaks, but with this line, it works fine after it's init and done with (probably because of the update and pulls from the NPC sheet right afterwards

In the old code for Earthdawn, it doesn't flag an error at all,
the exact same script file into CoreRPG, makes it show an error. I believe it's something to do with how old the code is for Earthdawn could be for a different set of values. I'm working to clean it up... but this one has me stumped.

Link to screen shot regarding the error and code directly: https://puu.sh/jMDwM/90837357ac.png

Trenloe
August 24th, 2015, 16:01
OK. So, valuefield[1] isn't valid at this point (within the onInit function).

valuefield[1] might be trying to access the XML parameters of the valuefield control. See the "Accessing XML parameters from script" section here: https://www.fantasygrounds.com/modguide/scripting.xcp

For example (taken from the Earthdawn ruleset):

<numberfield name="initstep" source="initiative.step">
<anchored>
<to>charframe</to>
<position>insidetopleft</position>
<offset>175,75</offset>
<size>
<height>25</height>
<width>25</width>
</size>
</anchored>
<frame>
<name>modifier</name>
<offset>5,5,5,5</offset>
</frame>
<font>sheetnumber</font>
<readonly />
<valuefield>initstep</valuefield>
<description>Initiative</description>
<script file="scripts/init_control.lua" />
</numberfield><!--}}}-->

The onInit function in init_control.lua refers to valuefield[1] for this control.

valuefield here is a XML parameter within the control definition. valuefield[1] will be referring to the value = initstep

If you don't have an XML parameter called "valuefield" in your control definition XML then that will cause this error.

Jacklifear
August 24th, 2015, 19:01
I'm sorry... I couldn't see your post through the beam of light because you, sir, are a godsend!!!

I'll dive into this when I get home. Thank you so much, updates soon

Jacklifear
October 10th, 2015, 23:06
So, I've been toying with this off and on and finally have time to push forward. Right now, I can't find out how to create it as an XML parameter based on what was stated before and a significant amount of google searches. Is there anyone willing to take 5-10 minutes and have a verbal conversation to handle this swifter than a set of posts back and forth?

damned
October 11th, 2015, 08:56
I *think* you need to define valuefield in something like template_common.xml or template_campaign.xml