PDA

View Full Version : Linking Checkboxes in Combat Tracker?



PneumaPilot
November 8th, 2008, 21:27
In the nWoD ruleset I am working on, I am trying to get the combat tracker to inport the health information from a character sheet. I store all of the health information in checkbox items and healthbox items (a custom made hybrid checkbox). How would I go about linking the states of these items between the character sheet and the combat tracker?

Foen
November 9th, 2008, 06:04
I suggest you take a look at the code for linked number fields in the d20 combat tracker, here is the HP field code:


<numbercontrol name="hp">
<anchored>
<to>initresult</to>
<position>right</position>
<offset>5,0</offset>
<size>
<width>34</width>
</size>
</anchored>
<font>sheetnumbersmall</font>
<frame>
<name>modifier</name>
<offset>2,2,2,2</offset>
</frame>
<script>
function onLinkUpdated(source)
setValue(source.getValue());
end

function onValueChanged()
if linknode then
linknode.setValue(getValue());
end
end

function setLink(dbnode)
if dbnode then
linknode = dbnode;
linknode.onUpdate = onLinkUpdated;
onLinkUpdated(linknode);

addBitmapWidget("indicator_linked").setPosition("bottomright", -5, -5);
end
end
</script>
</numbercontrol>

For a checkbox, the bitmap widget could look a bit odd, so you might try experimenting with/without the widget.

Foen

PneumaPilot
November 9th, 2008, 13:59
Well, you know, I was looking at that, but I thought maybe things could be handled without invoking the <script> tags. I wondered if maybe you could just put source="" kind of stuff.

Hmm, this is a little more esoteric that I would have liked. I'm going to have to try to understand all of this source and link stuff to be able to do this.

Foen
November 9th, 2008, 14:32
You're gonna have to get your hands dirty on this one, I think.

PneumaPilot
November 9th, 2008, 14:38
Aww gross. Oh well, I'll give it a shot this afternoon and post my (hopefully) happy results. Just one thing, though; How do you tell the combat tracker that you want to link back to the database associated with the character sheet? I think I saw in the D20 version that the name field got linked back through an association with the token. Is that right?

Foen
November 9th, 2008, 20:59
Hmm, I it saves a reference to the database node path. Looking in combattracker_entry.lua, there is a store() method which saves the database node path (node.getNodeName()).

When it is reloaded, the linked control values are restored relative to this path.

Foen

PneumaPilot
November 9th, 2008, 21:55
In the combattracker.lua file, in the addPC function it has a place where it links fields in the tracker to fields in the charsheet. I have made links here to all of the health boxes that I'll need. Also, in the utility_combattracker.xml file, I have added script functions to pass changes back along the link in the same what that the D20 rulset did with hp, as you copied above. I can't see anything wrong with the code, but I also can't really test it without one of my players logged in (or can I?).

I'm about to start work on the NPC/Personalities window, so at least I'll be able to try out the linking there.

Bidmaron
November 9th, 2008, 22:03
Why wouldn't starting up your own client using localhost work? Aside from the external ip, it is essentially the same as having someone log onto your host. To do so, simply start up FG2 again and select the Join a Game button. You must change the name to some other name other than the one you're using as a host (then when you startup again as host, you have to retype-in your host name). In the address box, simply type 'localhost' and then hit <Start>. You should be able to do everything you need from this client.

PneumaPilot
November 10th, 2008, 02:42
Okay, I'll try to follow those instructions. When I tried something similar before, it had some error message about duplicate license keys.

Oberoten
November 10th, 2008, 12:47
You need to connect using either the words : Localhost or the numbers 127.0.0.1 and both instances on the same computer.

Tarostar
November 10th, 2008, 16:38
In the nWoD ruleset I am working on, I am trying to get the combat tracker to inport the health information from a character sheet. I store all of the health information in checkbox items and healthbox items (a custom made hybrid checkbox). How would I go about linking the states of these items between the character sheet and the combat tracker?

Just to let you know I've been trying to do exactly the same thing. I'm linking a checkbox on the charsheet with a checkbox on the combattracker (this is for ignoring pain and there might be others in the future).

I used the setLink, etc. method used for other fields with no luck. I then looked at template_checkbox.lua (which the checkbox template uses) and its setState and getState methods and used those instead. It still doesn't work, but I've been distracted by other combattracker issues so haven't looked at it yet. I'm pretty sure this is the way to go though, although bear in mind I've not got it working yet and so might very well be wrong.

So I think instead of:


function onLinkUpdated(source)
setValue(source.getValue());
end


You would want:


function onLinkUpdated(source)
setState(source.getState());
end


You would need similar modifications to function onValueChanged, which if I recall I don't even have in my code... hmmm.

Let me know when you figure it out and I'll do the same.

PneumaPilot
November 10th, 2008, 17:30
Hmm, that's a good thought. I will try it if my current set-up doesn't work. I haven't tried logging into my own game with the localhost thing yet. I work mainly on Linux and have to reboot to XP to start up FG.

Tarostar
November 10th, 2008, 22:39
This piece of code works:



<checkbox name="ignorepain">
<anchored>
<to>impairment</to>
<position>right</position>
<offset>5,0</offset>
<size>
<width>25</width>
</size>
</anchored>
<script>
function onLinkUpdated(source)
super.setState(source.getValue());
end

function setLink(dbnode)
if dbnode then
linknode = dbnode;
linknode.onUpdate = onLinkUpdated;
onLinkUpdated(linknode);
end
end
</script>
</checkbox>

PneumaPilot
November 10th, 2008, 23:15
Cool. That's exactly what I have in my code, I just haven't tested it yet. Glad it works. Thanks for pointing out the setState thing!

PneumaPilot
November 14th, 2008, 21:34
I think there's something else I need to do in the combattracker_entry.lua file also, because this is crapping out on me.

PneumaPilot
November 14th, 2008, 21:35
Oh wait. I just noticed you have 'super.setState'. I left out the 'super'! Must try this...

PneumaPilot
November 14th, 2008, 23:37
Okay, it's finally working so that it will properly import current healthbox information into the tracker when a character's token is dragged to the tracker. It will even update the information in the tracker if the healthboxes on the character sheet are changed. However, it will not update the character sheet if the healthboxes on the tracker are changed. What am I doing wrong here?

Foen
November 15th, 2008, 06:41
I think you are missing one of the functions from the original script block (onValueChanged), so that needs to be added to your code and amended to work with check boxes rather than normal data fields. There is a problem, however, with the standard code which can cause an infinite loop so I've modified other areas of the code too:



function onLinkUpdated(source)
local flag=true;
if not source.getValue() then
--[[ convert the number value to a boolean ]]
flag=false;
end
if super.getState()~=flag then
--[[ only called if the new state is different from the old one ]]
super.setState(flag);
end
end

function onValueChanged()
if linknode then
if getState() then
linknode.setValue(1);
else
linknode.setValue(0);
end
end
end

function setLink(dbnode)
if dbnode then
linknode = dbnode;
linknode.onUpdate = onLinkUpdated;
onLinkUpdated(linknode);
end
end

Hope that does the trick, but I am just aware that I have assumed you are using standard check boxes but I think you have already modifed them to show more than two states (unchecked, checked, crossed and asterisked), so please shout if this code somehow breaks that functionality.

Foen

PneumaPilot
November 15th, 2008, 16:10
Well, I monkeyed around with onValueChanged in a similar way, but I could never get it to do anything. I didn't get any error messages, but I didn't get any results either. I'll check our your code as soon as I can (I probably put a 'super' in the wrong place - I don't know the scope of practically any of these functions). Thanks for the help.

PneumaPilot
November 15th, 2008, 16:29
Yep, I had a blasted 'super' in the wrong place. Thanks a ton, Foen, it works great!