PDA

View Full Version : Anchoring issue ...



GrimmSpector
February 27th, 2016, 21:49
The first piece of anchor code works just fine, and the control gets rendered, but I get an error in console, and it's not being rendered in quite the right place, answer is as below. Can anyone share with me why? Ideally I want to get this new control lined up with the control I'm anchoring to vertically, but they're of differing sizes, and the parent control is dynamically anchored.

Error: Ruleset Error: window: No vertical anchor defined for control (standard1) in windowclass (charsheet_main)



newPip.setAnchor("left", "standarddamage_label", "right", "relative", 5);
newPip.setAnchor("bottom", "standarddamage_label", "bottom", "absolute", 0);

GrimmSpector
February 29th, 2016, 15:00
Can nobody enlighten me on this issue?

Trenloe
February 29th, 2016, 16:00
See the info in the setAnchor interface definition: https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#setAnchor

"Anchored controls should either be anchored at opposite sides (left and right, or top and bottom) or have one anchor and a width or height directly specified (see setAnchoredWidth and setAnchoredHeight)."

GrimmSpector
February 29th, 2016, 16:13
Ah that's annoying, so I can't set them to have their bottoms at the same height if they're of differing heights, I'll have to calculate an offset. Ok, thanks!

Trenloe
February 29th, 2016, 16:25
Ah that's annoying, so I can't set them to have their bottoms at the same height if they're of differing heights, I'll have to calculate an offset. Ok, thanks!
Anchor to the bottom and then set the height. https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#setAnchoredHeight

GrimmSpector
February 29th, 2016, 16:48
Ok, I gave the setAnchorHeight a try, gave it "12" as a string, got:

Ruleset Error: window: No vertical anchor defined for control (standard1) in windowclass (charsheet_main)
Script Error: [string "standard"]:1: attempt to call field 'setAnchorHeight' (a nil value)

One of the controls, the first one standard1 does seem to show up on the sheet. and "standard" is showing up fine where it should...here's the pertinent code:



<stringcontrol name="standarddamage_label">
<anchored to="combatdataframe" position="insidetopleft" offset="10, 25" height="10" />
<font>sheetlabelinline</font>
<static>Standard Damage</static>
</stringcontrol>
<simplenumber name="standard">
<anchored to="combatdataframe" position="insidetopright" offset="10,10" />
<readonly />
<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
if i == 1 then
newPip.setAnchor("left", "standarddamage_label", "right", "relative", 5);
newPip.setAnchor("bottom", "standarddamage_label", "bottom", "absolute", 0);
newPip.setAnchorHeight("12");
else
newPip.setAnchor("left", "standard" .. tostring(i-1), "right", "relative", 1);
newPip.setAnchor("bottom", "standarddamage_label", "bottom", "absolute", 0);
newPip.setAnchorHeight("12");
end
end
end
</script>
</simplenumber>

Trenloe
February 29th, 2016, 18:02
You're still anchoring on non-opposite sides. As mentioned above: "Anchored controls should either be anchored at opposite sides (left and right, or top and bottom) or have one anchor and a width or height directly specified (see setAnchoredWidth and setAnchoredHeight)."

To help you troubleshoot exactly which command is causing the error, put Debug.console statements before each of the newPip. lines in your code. But, I'm guessing, it's more than likely the "bottom" set anchor as this isn't opposite to the "left" anchor.

GrimmSpector
February 29th, 2016, 21:08
Ok, perhaps I'm misunderstanding something here, but there's no way I can put both a left and right anchor on these elements, as there's nothing to the right of them when they're instanced, and each one wants it's left side connected to the right of the one before it.

They all want to be at the same vertical height and size, and for that to be in line with the bottom of the label.

If I set only a left anchor, it tells me I'm wrong, if I try to do a weird thing like set the left anchor to the bottom side, which makes no logical sense to me, it tells me I'm wrong. If I try to set the bottom to anchor to the bottom, which logically should mean putting the bottom edge of each control at the same y coordinate, it tells me I'm wrong.

I can't set anything to be to the TOP anchor because then the size would be wrong with this method, or the location would be wrong.

The wording of your setanchorheight method isn't clear, but it's indicating to me I should be using either the top anchor, or the bottom anchor. But if I can only anchor them to the opposite sides then we have an issue. I am pretty sure at other places in code, I have elements anchoring their tops to the tops of frames and other controls and offsetting slightly down, and behaving exactly as I would expect and am trying to do here...

Trenloe
February 29th, 2016, 21:45
As mentioned above - you need one of two things: opposite anchors (top & bottom or left & right), OR one anchor and the corresponding setAnchoredHeight or setAnchoredWidth.

To create a control FG needs to know four different things to be able to get the whole dimensions for the control:

The x coordinate (horizontal position of the left edge)
The y coordinate (vertical position of the top edge)
The width of the control
The height of the control

See "Static Bounds" here: https://www.fantasygrounds.com/modguide/windowing.xcp

This is the important part: If you use anchoring, the control inherits 3 of the above 4 parameters from the control it is being anchored to. Using an anchor of "bottom" will inherit the x, y and width data from the control - but there is no height data available. This will come from specifying the height of the control OR specifying the anchor control on the opposite side as well ("top" in this case).

See "Anchoring" here: https://www.fantasygrounds.com/modguide/windowing.xcp

Try setting the height of the control first - either in the control's XML definition or using setAnchoredHeight, before you use setAnchor.

Moon Wizard
February 29th, 2016, 21:49
Unless you are using the staticbounds tag to explicitly set a placement for a control, each control must have full placement information:
* A left and right anchor defined, OR a left or right anchor plus a width
* A top and bottom anchor defined, OR a top or bottom anchor plus a height

Other thoughts:


If anchors refer to other controls, those other controls must be defined in the windowclass definition (or added via the API) prior to the control you are setting the anchors on.
The correct function for setting the anchored height is setAnchoredHeight(#) and the correct function for settings the anchored width is setAnchoredWidth(#)
All the original error is saying is that you are creating a control with no vertical placement information. Try setting the default state of the template you are instantiating to invisible, and then making visible after you set the anchors/height/width.


Again, I will make a plea to save your sanity. You should begin with statically defining the placement of your controls on your sheets. It's MUCH easier in the short term. All of the rulesets that I've built were started that way, and only later did I decide to add templates, anchors and other complexities. I feel that you are making this harder than it needs to be to build a sheet, and I'd rather see you finish than get bogged down in technical issues.

Regards,
JPG

GrimmSpector
March 1st, 2016, 01:48
Procedural placement of the controls shouldn't be such a problem really.

That aside, if I explicitly set things, sure it would function, but since I plan to do a lot of visual tweaking and changing of image assets, having it change more on the fly is in the long run better.

In addition, (and I should've posted the xml template for you), the size, both height and width are already explicitly set in the xml, so that takes care of both of those. And the control is anchoring just fine to the right side o the control before it, or the static label if it's the 1st control.

The only issue I'm having is in the y direction, trying to get the bottom of one control to line up with the bottom of another, without having to manually set the y coordinate(s); this is easily achieved normally when putting together an xml with the position codes for instance, so it shouldn't be an issue.

GrimmSpector
March 1st, 2016, 04:18
If I attempt this instead:



<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
if i == 1 then
newPip.setAnchor("left", "standarddamage_label", "bottom", "relative", 5);
newPip.setAnchor("top", "standarddamage_label", "bottom", "relative", newPip.height - window.standarddamage_label.size.height);
else
newPip.setAnchor("left", "standard" .. tostring(i-1), "bottom", "relative", 1);
newPip.setAnchor("top", "standard" .. tostring(i-1), "bottom", "relative", -newPip.Height);
end
end
end
</script>


I receive the errors:

Ruleset Error: window: No vertical anchor defined for control (standard1) in windowclass (charsheet_main)
Script Error: [string "standard"]:1: attempt to index field 'size' (a nil value)
Ruleset Error: window: No vertical anchor defined for control (standard1) in windowclass (charsheet_main)

I've tried .height, and .size.height, can't seem to access it's height property; that aside, it still wants to tell me there's no vertical anchor defined. It tells me this even if I use a static number for the offset value; but when it's a 0 offset, it somehow is dropping the control in the middle of the window, and NOT to the direct right of the control it's anchored to the left side of...

Trenloe
March 1st, 2016, 04:35
In your code in post #12 you're trying to anchor the top and the left side of the control - this *does not give you the height of the control* - which is why you are getting the *no vertical anchor defined error*.

This has been explained multiple times in this thread. I'm not going to respond anymore as I'm getting frustrated, as I'm sure you are too.

GrimmSpector
March 1st, 2016, 04:45
In your code in post #12 you're trying to anchor the top and the left side of the control - this *does not give you the height of the control* - which is why you are getting the *no vertical anchor defined error*.

This has been explained multiple times in this thread. I'm not going to respond anymore as I'm getting frustrated, as I'm sure you are too.

Did you just ignore the part where I told you the control already had an explicit height defined in it's definition then? Defined in the XML, which coincidentally was one of the things you asked me to do, which I had already done. It's in fact defined with explicit width and height, and without an anchor draws itself in the middle of the window, with errors in console, at the size I want it to be just fine. So clearly that isn't the problem.

I guess I'm just wasting my time asking these questions then.

damned
March 1st, 2016, 05:33
Did you just ignore the part where I told you the control already had an explicit height defined in it's definition then? Defined in the XML, which coincidentally was one of the things you asked me to do, which I had already done. It's in fact defined with explicit width and height, and without an anchor draws itself in the middle of the window, with errors in console, at the size I want it to be just fine. So clearly that isn't the problem.

I guess I'm just wasting my time asking these questions then.

GrimmSpector you ask some good and some complex questions. You have also been given both good answers and good advice.
The answer that Trenloe gave 3x was confirmed by Moon Wizard along with repeating some good advice.
You are obviously making some good headway on some things but coding in FG, coding a Ruleset, a detailed one, is a big undertaking and there is oodles of stuff to learn.
Go waaaaaay back and you will see some early posts by MW where he asks some realtively easy coding questions while he was still a community developer. He didnt code like a Robot from day one - he started with stuff he could handle before he built masterpieces like PF/4e and 5e.

Oh and I know how frustrating this is - I find this stuff very difficult!

GrimmSpector
March 1st, 2016, 05:47
GrimmSpector you ask some good and some complex questions. You have also been given both good answers and good advice.
The answer that Trenloe gave 3x was confirmed by Moon Wizard along with repeating some good advice.
You are obviously making some good headway on some things but coding in FG, coding a Ruleset, a detailed one, is a big undertaking and there is oodles of stuff to learn.
Go waaaaaay back and you will see some early posts by MW where he asks some realtively easy coding questions while he was still a community developer. He didnt code like a Robot from day one - he started with stuff he could handle before he built masterpieces like PF/4e and 5e.

Oh and I know how frustrating this is - I find this stuff very difficult!

Yes, thank you damned. I appreciate the advice, the issue here is that I've done precisely what Moon Wizard and Trenloe have told me, and it's not provided the expected results, and Trenloe seems to feel that I'm somehow ignoring his advice.

Building up a character sheet, or display some imagery, and so forth are all simple, easily handled things, that can teach me the things I don't know about the system in theory. So I'm working on these things. There are no small extensions that currently interest me, so it's really the only option.

I am neither new to programming or scripting, nor am I looking for things to be easy.

I've created a control with explicit width, height and two set anchors, when I set similar controls up in xml using the anchors as parents (i.e. specifying each anchor separately in tags, rather than a single anchor to tag), I get expected results, when providing for the same through script, I get errors, for which there's been no satisfactory answer when I do precisely what's been asked I try to do. Evening skipping the dynamic portion, since it's not getting that far as it's throwing the error on the very first control, which is effectively a single static element, the error is an issue.

If I have a control with:
- Static set width
- Static set height
- An anchor specifying lateral window position
- An anchor specifying vertical window position

The control should be able to be drawn. If we look at it as a mathematical bounding box where we're taking it in cartesian tuples (x, y) to (x+n, y+m), assuming that n and m are integer heights in pixels, an anchor to between two controls y locations, be they top of bottoms should be equivalent from a programming stand point. Assuming every control is done from top left, then (x+n, y+m) representing the bottom right corner, then wanting a control to anchor along the lower y coordinate would mean both controls second corner have a y coordinate of y+m.

It's really very simple, and how things in other programming languages and environments typically work. And what I would expect of something like this. If this isn't how it works, which is implied by the less than clear entry in the reference document that's fine. But when I receive the exact same error when I do define OPPOSITE sides of the control, which is completely arbitrary, then there must be some other underlying problem.

Since it's not the size which has been defined explicitly, and then in one of the code attempts defined AGAIN in the code to the same value, with no change in the error thrown. And since controls can be setup to be bound to the TOP of a frame, with their TOP anchored to that TOP coordinate. I'm at a complete loss as to what the true underlying issue is at this point.

Moon Wizard
March 1st, 2016, 06:46
I'm not trying to sound like a broken record, but you are still attempting to write very complex code of dynamically generated controls at runtime. While not impossible, it is the hardest possible way to build sheets, since there is no good debugger for Lua especially in a sandbox like in FG.

I think the challenge we are facing is that we are suggesting an implementation strategy to you, but you ignore our suggestions to take the more difficult route.

Learning to program the FG interface works best when you can copy a working example, and tweak it to get what you want. Building from scratch is much more difficult, and leads to the kind of challenges you are facing.

Some more thoughts:

Again, I would like to step back and ask what you are trying to design. Is it like something in an existing ruleset? If so, you should borrow from there.

Perhaps it would work best to show us a mockup of the sheet section you are trying to build, and we can suggest a strategy.

If you are adding a set of attributes less than ten, just hard code their locations using relative anchors for placement. This is used for attributes in every D&D ruleset.

If you are adding a whole list of more than ten, especially if it may later be expanded (such as skills); look at the model for skills in the D&D rulesets.

Regards,
JPG

GrimmSpector
March 1st, 2016, 15:53
Thanks Moon Wizard, and I'm sorry if you feel like I'm ignoring your suggestions, I am in fact not disregarding them, but I am not implementing all of them in 100% of what I do either. As a programmer, I favour efficiency, and flexibility in things I write. Debugging certainly is a challenge in this environment.

I'm working up a Battletech character sheet and eventually full ruleset. I'm attempting to emulate the health pips used in their character sheets, which I also intend to adapt to work for mechs, which could be hundreds of pips. In this case, character sheets typically carry a set of 40 pips for standard damage, and 40 for fatigue based damage. In my first iteration I'm attempting to setup a static set (10), of them to explore their properties and ways of aligning and counting them, and addressing them. Once I have a good handle on that I intend to make the full set of 40, and dynamically update the graphical asset representing them as the character receives or heals damage, or changes their BOD/WIL attributes as appropriate.

The hierarchical structure of the GUI is strange in this system, but I am learning as we go. The issue I had with the dynamic attributes is no longer an issue, and working with them now is quite easy, while they're still being dynamically assembled. While it's certainly more complex, it's allowed me to learn more than if I simply copied the simpler method, and stuck with that instead of exploring how things actually functioned.

It also allowed me to more fully explore the setup of the combo box controls to get results more along the lines of what I was aiming for, which was quite helpful overall. So the help of yourself, Trenloe, damned and dulux-oz has been very useful to me. My goal is not to frustrate you guys.

The reason I'm not making these static is that I may reorganize where the set appears on the sheet, and change their vertical/horizontal area they're allowed to take up many times while I find a good layout. And the number of pips shown to the player may change frequently, though the area they take up will not once I have the final setup decided. The size of the icons being used will also likely change when I make or acquire a new asset for them, so a method of setting them vertically in relation to each other regardless of size, and having the first row be vertically inline with their text label is ideal.

Now that I think about it, it may bear some similarities to the code used for the checkboxes on spell prep in the 3.5E/PF rulesets.

GrimmSpector
March 1st, 2016, 17:20
Edit: So after throwing in some debugs, turns out it's not using the height/width from the xml...can anyone share with me why? This would be far easier if it were.



<template name="health_pip">
<genericcontrol>
<size>
<width>12</width>
<height>12</height>
</size>
<script>
function onInit()
local pipWidget = addBitmapWidget("button_checkoff");
pipWidget.setPosition("center", 0, 0);
end
</script>
</genericcontrol>
</template>


I've also been examining some anchor sets in other rulesets that don't use "opposite" sides, they just use setAnchor("bottom", nil, "bottom", "absolute", #), I feel like this method may be able to produce my desired result.

Despite the fact that it's not obeying my width/height, sometimes the controls do display, though not in the right locations, but using setAnchoredHeight("12") doesn't seem to avoid the vertical anchor error.

damned
March 1st, 2016, 22:18
Hi GrimmSpector - Im not nearly as good at this as you so I cant follow your code but in most of the snippets with anchors you still are not following this rule:
you need one of two things: opposite anchors (top & bottom or left & right), OR one anchor and the corresponding setAnchoredHeight or setAnchoredWidth
I hear you when you say that doesnt work for you because there is nothing on teh right and you have different height boxes that need to bottom align AND you want it dynamic... but you have to work out a way to apply this rule to your design choices. the rule doesnt bend, you need to work with it.

GrimmSpector
March 1st, 2016, 23:38
Hi GrimmSpector - Im not nearly as good at this as you so I cant follow your code but in most of the snippets with anchors you still are not following this rule:
you need one of two things: opposite anchors (top & bottom or left & right), OR one anchor and the corresponding setAnchoredHeight or setAnchoredWidth
I hear you when you say that doesnt work for you because there is nothing on teh right and you have different height boxes that need to bottom align AND you want it dynamic... but you have to work out a way to apply this rule to your design choices. the rule doesnt bend, you need to work with it.

The height and width are explicitly set out for the control in the xml before it's initiated, so I should only need to know the where, not the size. I've set a Left side anchor, which should take care of the x, and setting a y anchor in any fashion should satisfy all of the conditions.

For some reason, as per my last post, it looks like that system is ignoring the xml block:



<anchored>
<size>
<width>12</width>
<height>12</height>
</size>
</anchored>


So the issue doesn't appear to be with the anchor at all.

As an example that I'm pretty sure is doing something similar to what I'm trying to do (for general layout, not dynamic controls), there are various things in the corerpg set that do things like this:



setAnchor("bottom", nil, "bottom", "absolute", -40);


Most of the ones I've found have been confined to the various desktop panels, but they're just windows like the rest, they're just confined to being the bottom layer, and from what I can tell need to have static dimensions.

I'm assuming a statement like this is saying to draw within it's containers area at the 40 pixels from the bottom. I could be wrong. I've also seen similar constructs that replace the "nil" argument with an empty string "".

damned
March 1st, 2016, 23:42
GrimmSpector the fact that defining the XML dimensions in this way works in other systems/environments/platforms is no guarantee that it will work in the FG environment. You have to do it with methods that FG supports.

damned
March 1st, 2016, 23:57
GrimmSpector can you pack it up and send it to me via dropbox in a PM along with steps to reproduce?
Ill see if I can bridge this communications gap! :)

GrimmSpector
March 2nd, 2016, 00:10
Not sure there's a communications gap.

Normally controls inherit whatever properties are given in their definition.

Given that the control has no lua method for setting it's size outside of anchoring, and when I DO use the anchor method to set a height it still throws the error, I'm definitely at a loss. But if I can at least find out WHY it's not using it's xml definition, but will sometimes still draw appropriately sized, that might get me moving in a helpful direction. I'm going to probably start from scratch on it, and try some other method later.

GrimmSpector
March 2nd, 2016, 03:07
Caught a spelling error in my code, fixed it, got things rendering more or less in the right place, however I'm still getting the error. I assume it's because I'm still using the bottom tags, going to experiment with "opposites" to see how things go. Strange that I get them in the right place, but the error still persists. What seems really strange still is that the size is still reporting back as (0,0), despite being explicitly set, and I feel like this must be the key or at least important to the issue I'm having.

GrimmSpector
March 2nd, 2016, 03:20
EDIT: Duplicate post somehow...sorry about that!

GrimmSpector
March 2nd, 2016, 03:21
Ok, so using the opposite pair changes nothing, here's a screenshot and all associated code:

This is the label that the first pip anchors to, a number control that's currently unused initiates all the code, it's on the right side in the lower box of the screenshot; and the script initiates the little circular pips in the image.



<stringcontrol name="standarddamage_label">
<anchored to="combatdataframe" position="insidetopleft" offset="10, 25" height="10" />
<font>sheetlabelinline</font>
<static>Standard Damage</static>
</stringcontrol>
<simplenumber name="standard">
<anchored to="combatdataframe" position="insidetopright" offset="10,10" />
<readonly />
<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
if i == 1 then
newPip.setAnchor("left", "standarddamage_label", "right", "relative", 5);
newPip.setAnchor("top", "standarddamage_label", "bottom", "relative", 2);
newPip.setAnchoredHeight("12");
else
newPip.setAnchor("left", "standard" .. tostring(i-1), "right", "relative", 0);
newPip.setAnchor("top", "standard" .. tostring(i-1), "bottom", "relative", 0);
end
local x,y = newPip.getSize();
Debug.console(x, y);
end
end
</script>
</simplenumber>


This is the template for the instanced controls:



<template name="health_pip">
<genericcontrol>
<anchored>
<size>
<width>12</width>
<height>12</height>
</size>
</anchored>
<script>
function onInit()
local pipWidget = addBitmapWidget("button_checkoff");
pipWidget.setPosition("center", 0, 0);
end
</script>
</genericcontrol>
</template>


And here's the image, should be all we need.

13215

And here's the debug from the console, as you can see each control still throws the vertical anchor error, and seems to be returning a width and height of 0, however each control must have a width as they're not all on top of each other, and the width and height are explicitly set in the xml of the template...any ideas guys?



Runtime Notice: Reloading ruleset
Ruleset Error: window: No vertical anchor defined for control (standard1) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard2) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard3) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard4) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard5) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard6) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard7) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard8) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard9) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Ruleset Error: window: No vertical anchor defined for control (standard10) in windowclass (charsheet_main)
Runtime Notice: #0 | #0
Database Notice: Campaign saved.



And I get the exact same error output, but the controls are not in the right places if I try adjusting the script with anchor heights/widths:



<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
if i == 1 then
newPip.setAnchor("left", "standarddamage_label", "right", "relative", 5);
newPip.setAnchor("top", "standarddamage_label", "bottom", "relative", 2);
newPip.setAnchoredHeight("12");
else
newPip.setAnchor("left", "standard" .. tostring(i-1), "right", "relative", 0);
newPip.setAnchor("top", "standard" .. tostring(i-1), "bottom", "relative", 0);
end
newPip.setAnchoredHeight("12");
newPip.setAnchoredWidth("12");
local x,y = newPip.getSize();
Debug.console(x, y);
end
end
</script>

damned
March 2nd, 2016, 13:46
Ill be honest - I still do not know exactly what you are trying to achieve.
However here is some code that gives me what I think you want - maybe it will help you.

template

<template name="number_standard">
<!-- basicnumber seems to be another template but I cant find it anywhere - maybe in CoreRPG? -->
<basicnumber>
<tooltip><text>Click to Edit.</text></tooltip>
<anchored position="right" offset="15,0" width="32" />
</basicnumber>
</template>
<template name="health_pip">
<genericcontrol>
<anchored>
<position>right</position>
<offset>0,-250</offset>
<size>
<width>0</width>
</size>
</anchored>
<script>
function onInit()
local pipWidget = addBitmapWidget("button_checkoff");
pipWidget.setPosition("center", 0, 0);
end
</script>
</genericcontrol>
</template>

charsheet

<label name="standarddamage_label">
<anchored to="primaryattributesframe" position="insidetopleft" offset="10, 25" height="10" />
<font>sheetlabelinline</font>
<static>Standard Damage</static>
</label>
<number_standard name="standarddmg">
<anchored to="standarddamage_label" position="right" offset="10,0" />
<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
Debug.console("newPip: ");
Debug.console("standard" .. tostring(i));
newPip.setAnchor("left", "standarddmg", "right", "relative", 15);
newPip.setAnchor("top", "standarddmg", "top", "absolute", 0);
local x,y = newPip.getSize();
Debug.console("x, y: ");
Debug.console(x, y);
end
end
</script>
</number_standard>

13218

GrimmSpector
March 2nd, 2016, 15:50
My description earlier in the thread wasn't clear enough? :P Oh well, I'll take a look at what you have here, and see, thanks either way for the attempt damned.


Edit: The number control is for reference only, and won't be part of the final sheet lol

GrimmSpector
March 2nd, 2016, 15:59
Ok, I've reviewed your code, so you're using anchors that are not opposites, like I initially tried to do, and it's not giving you any errors? And it's giving you back the width/height of the control?

And you're using the relative anchor method to get the pips to arrange laterally, as they can when you let it assume that he new bounds of the control are shifted by the first control anchored to it. I had considered doing it that way but wasn't sure it would give me the results I want in the end, the issue is that I'll be changing how many pips (40 total at the end of it all), and I'm unsure on the lateral space I'll be allowing in the end, so I want to set it up in a way that's easy to change how many rows I have of them, which is why I broke the loop up, with the intention that the only pip that would always 100% of the time be on row #1 would be pip #1, and the rest may or may not vary.

The only difference I see in your template is that you're giving position and offset which would be overwritten by the anchor methods anyways. You also didn't specify a height, which Trenloe complained about my code was an issue, even though I explicitly set it in the template.

So I'm not sure why your code would work, and mine would not. You've even given it a width of 0, and rely on offsetting them from each other to space out the images in the end, which is functional in this setup.

You asked about basicnumber, it is indeed from corerpg, it's just a numberfield really, and not important as it's just displaying a reference value for me while working on the sheet.

Trenloe
March 2nd, 2016, 17:00
I've reviewed your code, so you're using anchors that are not opposites
100% incorrect.

The reason this works is that there are opposite anchors in this code, a right anchor in the XML:

<genericcontrol>
<anchored>
<position>right</position>
<offset>0,-250</offset>
<size>
<width>0</width>
</size>
</anchored>

and a left anchor in the code:

newPip.setAnchor("left", "standarddmg", "right", "relative", 15);

left and right are opposite anchors.

Note: there is no need for the two setAnchor commands - the newPip.setAnchor("top"... is not needed at all. The code that is needed:



function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
Debug.console("newPip: ");
Debug.console("standard" .. tostring(i));
newPip.setAnchor("left", "standarddmg", "right", "relative", 15);
local x,y = newPip.getSize();
Debug.console("x, y: " .. x .. ", " .. y);
end
end


There is only one anchor here (left) to go with the right anchor in the XML - opposites only.


You also didn't specify a height, which Trenloe complained about my code was an issue, even though I explicitly set it in the template.
Read the "This is the really important part" here: https://www.fantasygrounds.com/forums/showthread.php?28570-Anchoring-issue&p=256588&viewfull=1#post256588

As the anchors being used here are left and right these automatically provide the x, y and height data as they are providing vertical edge anchors. As they are vertical edge anchors, the width is not provided - hence the need for opposite anchors to give the width (right - left = width).

The reason I kept going on, numerous times, about height was that you were using bottom anchors, which doesn't give the height of the control only x, y and width - and the error you were receiving was that the vertical (height) data was the issue.

The above completely supports all of the multiple posts I've made about opposite anchors needed to make this work.

Here are your 10 pips, using only opposite anchors - one in the XML and one in the LUA:

https://dl.dropboxusercontent.com/u/39085830/Screenshots/Pips%20test.jpg

GrimmSpector
March 2nd, 2016, 19:06
100% incorrect.

The reason this works is that there are opposite anchors in this code, a right anchor in the XML:

<genericcontrol>
<anchored>
<position>right</position>
<offset>0,-250</offset>
<size>
<width>0</width>
</size>
</anchored>

and a left anchor in the code:

newPip.setAnchor("left", "standarddmg", "right", "relative", 15);

left and right are opposite anchors.

Note: there is no need for the two setAnchor commands - the newPip.setAnchor("top"... is not needed at all. The code that is needed:



function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
Debug.console("newPip: ");
Debug.console("standard" .. tostring(i));
newPip.setAnchor("left", "standarddmg", "right", "relative", 15);
local x,y = newPip.getSize();
Debug.console("x, y: " .. x .. ", " .. y);
end
end


There is only one anchor here (left) to go with the right anchor in the XML - opposites only.


Read the "This is the really important part" here: https://www.fantasygrounds.com/forums/showthread.php?28570-Anchoring-issue&p=256588&viewfull=1#post256588

As the anchors being used here are left and right these automatically provide the x, y and height data as they are providing vertical edge anchors. As they are vertical edge anchors, the width is not provided - hence the need for opposite anchors to give the width (right - left = width).

The reason I kept going on, numerous times, about height was that you were using bottom anchors, which doesn't give the height of the control only x, y and width - and the error you were receiving was that the vertical (height) data was the issue.

The above completely supports all of the multiple posts I've made about opposite anchors needed to make this work.

Here are your 10 pips, using only opposite anchors - one in the XML and one in the LUA:

https://dl.dropboxusercontent.com/u/39085830/Screenshots/Pips%20test.jpg

Ok, I guess what I wasn't understanding is how position information in the xml control does anything, as I assumed the positions in the xml control were arbitrarily defined by the face that it was given x and y values for it's size.

I apologize that I didn't understand that, and it led to so much frustration. I think based on this information I can construct something much more suitable to the task, and I do appreciate the help.

GrimmSpector
March 3rd, 2016, 01:20
So my new problem....I can't get it to render anything beyond that initial 10. I've tried adding a "position" tag for another side to anchor to, seems to do nothing, and no matter what I try to anchor the new set to, nothing appears, the original 10 draw fine.

The really weird thing, the debug console is no longer registering the print messages; they're not outputting to the console, I put them there wondering if execution was stopping somehow, but it looks like I won't be able to tell for some reason, which is pretty frustrating. Not sure why the console is empty.

Control & script:


<simplenumber name="standard">
<anchored to="combatdataframe" position="insidetopright" offset="10,10" />
<readonly />
<script>
function onInit()
Debug.console("Set 1");
for i=1,10 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
newPip.setAnchor("left", "standarddamage_label", "right", "relative", -4);
newPip.setAnchor("top", "", "top", "relative", 28);
end
Debug.console("Set 2");
for i=11,30 do
local newPip = window.createControl("health_pip", "standard" .. tostring(i));
newPip.setAnchor("top", "standarddamage_label", "bottom", "absolute", 10);
newPip.setAnchor("left", "", "left", "relative", -4);
end
Debug.console("Done!");
end
</script>
</simplenumber>


Template:



<template name="health_pip">
<genericcontrol>
<anchored>
<position>right</position>
<position>below</position>
<offset>0,0</offset>
<size>
<width>12</width>
<height>12</height>
</size>
</anchored>
<script>
function onInit()
local pipWidget = addBitmapWidget("button_checkoff");
pipWidget.setPosition("center", 0, 0);
end
</script>
</genericcontrol>
</template>


I'm sure you're plenty frustrated Trenloe, but I though I had a handle on this, I also tried the method of doing the individual side tags, i.e. "bottom", "left", "right" etc., with their associated information, not including a parent of course as that was going to be set on the fly, and got some pretty weird results.

damned
March 3rd, 2016, 01:47
try this -

13221

template


<template name="number_standard">
<!-- basicnumber seems to be another template but I cant find it anywhere - maybe in CoreRPG? -->
<basicnumber>
<!-- Tooltip - for HoloGnome -->
<tooltip><text>Click to Edit.</text></tooltip>
<anchored position="right" offset="15,0" width="32" />
</basicnumber>
</template>
<template name="health_pip1">
<genericcontrol>
<anchored>
<position>right</position>
<offset>0,-250</offset>
<size>
<width>0</width>
</size>
</anchored>
<script>
function onInit()
local pipWidget = addBitmapWidget("button_checkoff");
pipWidget.setPosition("center", 0, 0);
end
</script>
</genericcontrol>
</template>
<template name="health_pip2">
<genericcontrol>
<anchored>
<position>right</position>
<offset>0,-227</offset>
<size>
<width>0</width>
</size>
</anchored>
<script>
function onInit()
local pipWidget = addBitmapWidget("button_checkoff");
pipWidget.setPosition("center", 0, 0);
end
</script>
</genericcontrol>
</template>

charsheet


<!-- Standard Damage -->
<label name="standarddamage_label">
<anchored to="primaryattributesframe" position="insidetopleft" offset="10, 25" height="10" />
<font>sheetlabelinline</font>
<static>Standard Damage</static>
</label>
<number_standard name="standarddmg">
<anchored to="standarddamage_label" position="right" offset="10,0" />
<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip1", "standard" .. tostring(i));
Debug.console("newPip: ");
Debug.console("standard" .. tostring(i));
newPip.setAnchor("left", "standarddmg", "right", "relative", 15);
newPip.setAnchor("top", "standarddmg", "top", "absolute", 0);
local x,y = newPip.getSize();
Debug.console("x, y: ");
Debug.console(x, y);
end
end
</script>
</number_standard>

<!-- Bonus Damage -->
<label name="bonusdamage_label">
<anchored to="primaryattributesframe" position="insidetopleft" offset="10, 48" height="10" />
<font>sheetlabelinline</font>
<static>Bonus Damage</static>
</label>
<number_standard name="bonusdmg">
<anchored to="bonusdamage_label" position="right" offset="24,0" />
<script>
function onInit()
for i=1,10 do
local newPip = window.createControl("health_pip2", "standard" .. tostring(i));
Debug.console("newPip: ");
Debug.console("standard" .. tostring(i));
newPip.setAnchor("left", "bonusdmg", "right", "relative", 15);
newPip.setAnchor("top", "bonusdmg", "top", "absolute", 0);
local x,y = newPip.getSize();
Debug.console("x, y: ");
Debug.console(x, y);
end
end
</script>
</number_standard>

its ugly code im sure. and a little verbose but very little to change between copy and paste sections.

damned
March 3rd, 2016, 01:51
the console is empty because the debug isnt getting executed which means the code is stopping earlier....
or you are not opening console BEFORE you open the character sheet. the debug is all in oninit code which is only running the first time you open the char sheet in that session.
before your console was opening automatically because of the height warnings.

GrimmSpector
March 3rd, 2016, 02:14
the console is empty because the debug isnt getting executed which means the code is stopping earlier....
or you are not opening console BEFORE you open the character sheet. the debug is all in oninit code which is only running the first time you open the char sheet in that session.
before your console was opening automatically because of the height warnings.

Nope, I'm opening it immediately after opening the sheet, and as per the screen shot I sent you in the PM, it is drawing the first 10 pips from the first loop, which means it needs to be at least writing ONE of the debug statements, and it isn't...sooooooooooo...that's nuts.

I know how to manually open the console and when to do so to get the information I want out of it, that's not an issue.

Also I think you're misunderstanding the goal here, as I'm not trying to instantiate another label and numberfield, the numberfield isn't even involved, it's for my reference, and may or may not be visible on the final sheet. The pips are all supposed to be tied to the label "Standard Damage". With some to the side, and some rows below, etc.

Eventually the ideal is to extend this code from character damage to vehicle damage, and in battletech vehicles have armor locations, and internal structure, the internal structure numbers are usually set values, but the armor values can fluctuate significantly, with certain maximums overall, and no minimums save of course 0.

damned
March 3rd, 2016, 02:28
the numberfield is irrelevant. i included it because you had included it originally. i spent 2 hours last night testing all the permutations i could think of to make it work. the version i posted isnt how you wanted to code it but it works and works without errors which is why i posted it. i left the number in now because im not reworking the code. its an easy 3min fix - drop the template i used for that, delete the number code and anchor the pips direct to the label.
my debugging is all working.

damned
March 3rd, 2016, 02:35
ianmward go to sleep!

GrimmSpector Im sorry - i missed where you said there wouldnt be a second label. you might (for simplicity sake) create some sort of object below the first label so you can anchor your second row of pips across....

GrimmSpector
March 3rd, 2016, 02:47
ianmward go to sleep!

GrimmSpector Im sorry - i missed where you said there wouldnt be a second label. you might (for simplicity sake) create some sort of object below the first label so you can anchor your second row of pips across....

well now that you mention it, that would be significantly more simple, something like an empty string control, with a static width/height; thanks!

Also wasn't suggesting you rewrite the code again :) I appreciate the work you've already put in.

Still not sure why the debug statements aren't working though...

ianmward
March 3rd, 2016, 03:03
As damned said, you need to open the console before you open the sheet. It will only write to the console if it's open.

The console opens automatically on error which is why it was working before.


Nope, I'm opening it immediately after opening the sheet, and as per the screen shot I sent you in the PM, it is drawing the first 10 pips from the first loop, which means it needs to be at least writing ONE of the debug statements, and it isn't...sooooooooooo...that's nuts.

I know how to manually open the console and when to do so to get the information I want out of it, that's not an issue.

Also I think you're misunderstanding the goal here, as I'm not trying to instantiate another label and numberfield, the numberfield isn't even involved, it's for my reference, and may or may not be visible on the final sheet. The pips are all supposed to be tied to the label "Standard Damage". With some to the side, and some rows below, etc.

Eventually the ideal is to extend this code from character damage to vehicle damage, and in battletech vehicles have armor locations, and internal structure, the internal structure numbers are usually set values, but the armor values can fluctuate significantly, with certain maximums overall, and no minimums save of course 0.

GrimmSpector
March 3rd, 2016, 03:13
As damned said, you need to open the console before you open the sheet. It will only write to the console if it's open.

The console opens automatically on error which is why it was working before.

I'll try that. Or I may go back to using print statements, as they seem to print to console even when it's not open. Thanks.

GrimmSpector
March 3rd, 2016, 03:43
Alright, after much experimentation with all the new info, I think I have a much better understanding of anchors in FG, and have adjusted my general plans accordingly, thanks again everyone.

Moon Wizard
March 3rd, 2016, 18:42
Also, a quick note that all warnings and errors are saved in the console.log file in the FG data directory, but the only warnings/errors that show up in the console are those that have occurred since the console window was opened. When in doubt, check the console.log file. If it's not there, then the Debug.console statements are not firing.

You can also use Debug.chat to output messages to the chat window instead, so you don't have to worry about opening the console.

Regards,
JPG

GrimmSpector
March 3rd, 2016, 19:29
Also, a quick note that all warnings and errors are saved in the console.log file in the FG data directory, but the only warnings/errors that show up in the console are those that have occurred since the console window was opened. When in doubt, check the console.log file. If it's not there, then the Debug.console statements are not firing.

You can also use Debug.chat to output messages to the chat window instead, so you don't have to worry about opening the console.

Regards,
JPG

Thanks, that should be very helpful.