PDA

View Full Version : Databasenodes



Fenloh
October 18th, 2008, 05:52
And its me again....

I still dont get it right

I do have a field on the charsheet called "useedge" this is a Checkboxfield (it can have the values 0 or 1
in the db.xml it is saved "<useedge type="number">0</useedge>"
it is directly under <charsheet> <id-0001>

I am in the Chat_chat.lua and i need the Value of that specific field. How do i get it.

I tried

local v1 = 0;
v1=window.useedge.getValue()

(and some other stuff)
(error: attempts to index field "useedge" (a nil value), the Value in the Database is 1 though)


If i have understood the Syntax correctly, then the variable useedge is found in the actual window (charsheet with id-0001, that is where i am at that moment)

If the Char is named "player1"
and If i would be in the Combattracker

how would i then get that useedgevalue?

I am a bit confused, because of those errormessages

joshuha
October 18th, 2008, 06:07
The checkbox is a special template control that can generate a databasenode to store a number value. However, that means a getValue() isn't going to automatically return the database value as the control itself isn't a data field. What you have to do is essentially get the databasenode yourself.

How you reference it depends on where you are.
If you were on the character sheet itself you could do.
window.getDatabaseNode().getChild("useedge").getValue()

Normally if you are using a player on a combat tracker you are storing a link somewhere back to their db node ("charsheet.id-0001"). And then it would be nodelinkvariable.getChild("useedge").getValue() or alternatively DB.findNode("charsheet.id-0001.useedge").getValue()

Fenloh
October 18th, 2008, 08:11
First of all, thanks for the answer!

I am on the Charsheet atm, making a Dicerolle via Drag.
I tried window.getDatabaseNode().getChild("useedge").getValue()

but i still get an error:

"attempt to index a nil Value"


window refers to the actual Window i am on (charsheet.id-0001)

getDatabaseNode() gets a nodepoint, but what nodepoint?


getChild("useedge") i do understand it puts up the field "useedge".
I thought though, that it gets the Value already of that field.

I am still confused

The Date in the DB.xml reads like this:

<root version="2.2">
<charsheet>
<id-00001>
<useedge type="number">1</useedge>


The problem is, that several people say several things and actually none worked so far and i am not sure why. *sigh*

Fenloh

Foen
October 18th, 2008, 08:50
You might want to try some debug code using the console:


if getDatabaseNode() then
print(getDatabaseNode().getNodeName());
else
print("Database Node not found!");
end

That will either tell you the database node isn't available from your context (say an unbound control) or will give you the full path of the current context. From the full path, you should be able to work out the way to access your useedge node.

If you haven't used the console before, you can open it from within FG by typing /console.

Hope that helps

Stuart

Fenloh
October 18th, 2008, 09:26
Well it did help, at least to understand what happens

I found out, that from the chat_chat.Lua, where i am, i am actually not on the Charsheet anymore.. my bad that is.

Now, how do i get the Information i need from the Charsheet where i drag my Dice from to the chat (thats the name of the node atm)?

I know where the Info is that i want, i just cant find the right way to retrieve it.

Foen
October 18th, 2008, 09:53
You need to create a custom data object and attach it to the drag data. I suggest you place the full node path string in the custom data and then you can use DB.findNode(path) from within the chat_chat script to retrieve a reference to the node.

Hope that helps

Stuart

Foen
October 18th, 2008, 14:27
Custom data is used to pass information from a drag operation to the onDrop handler or the onDiceLanded handler. The dragdata structure is documented in the library here (https://www.fantasygrounds.com/refdoc/dragdata.xcp), but the following example should help.

It works something like this:


onDrag function
function onDrag(button,x,y,dragdata)
... other stuff ...
local mydata = {};
mydata.nodename = getDatabaseNode().getNodeName();
dragdata.setCustomData(mydata);
... other stuff ...
end



onDiceLanded or onDrop
function onDiceLanded(draginfo)
local mydata = draginfo.getCustomData();
if mydata and mydata.nodename then
print(mydata.nodename);
end
end


Hopefully that should give you some pointers.

Cheers

Stuart

Fenloh
October 18th, 2008, 19:27
Well thanks a lot for the Infos, they did help a bit.

One thing is strange. Even if i do have the correct Datanodes i cannot get the data from the Database. I can see them in the dm.xml, but i cant get to them.

e.g. I have a field woundmodifier on the same "window" I can receive the Data through "windows.woundmodifier.getValue()" in the db.xml there is no woundmodifier, there is a <stat><wound><modifier>2....

Well i am puzzeld because i thought the databasenodes are directed to the db.xml.

through the draginfo help i did get the needed data to the Chat_chat_lua and the code looks like this now:


function onDiceLanded(draginfo)

if ChatManager.getDieRevealFlag() then
draginfo.revealDice(true);
end

if draginfo.isType("dice") then
local aretens=true;
for i = 1, draginfo.getSlotCount() do
draginfo.setSlot(i);
dicelist = draginfo.getDieList();
local edgeuseage =0;
edgeuseage=draginfo.getCustomData();



local entry = {};
entry.font = "sheetlabel";

if dicelist then
local dicecount=table.maxn(dicelist);
local successes=0;
local failures=0;
local glitch = "leer";
local halfdice=0;
local explodetable = {};
local explodecount=0;



print(edgeuseage);
for c = 1, dicecount do
if dicelist[c].type == "d6" then
if dicelist[c].result==6 and edgeuseage>=1 then
successes=successes+1;
explodecount=explodecount+1
table.insert(explodetable, "d6");
elseif dicelist[c].result>= 5 then
successes=successes+1;
elseif dicelist[c].result ==1 then
failures=failures+1;

end

else
aretens = false;
end
end
if explodetable then
local explodedescription = "Exploderoll";
throwDice("dice", explodetable, 0, explodedescription);
end


halfdice = math.ceil(dicecount/2)
if halfdice <= failures then
glitch = "Glitch";
end
if halfdice <= failures and successes == 0 then
glitch = "Critical Glitch";
end
if glitch == "leer" then
entry.text = draginfo.getDescription() .. " Successes: (" .. successes .. ")";
end
if glitch == "Glitch" then
entry.text = draginfo.getDescription() .. " Successes: (" .. successes .. ")" .. " " .. glitch;
end
if glitch == "Critical Glitch" then
entry.text = draginfo.getDescription() .. " " .. glitch;
end
if explodecount>0 then
entry.text=entry.text .. " Exloded Dice: (" .. explodecount .. ")";
end
if draginfo.getDescription()=="Exploderoll" then
entry.text = draginfo.getDescription() .. " Successes: (" .. successes .. ") add succsesses to previous roll";
end
if User.isHost() then
entry.sender = GmIdentityManager.getCurrent();
else
entry.sender = User.getIdentityLabel();
end
else
entry.text = "No dice left roll.";
end

if aretens then

draginfo.setDescription(entry.text);
ModifierStack.reset();

end
end
end
end


my Problem here is, that if a second "explosion" happens edgeuseage is a nil Value and i get an error. This happens begause the draginfos customdata is gone with the exploding wole.

any Ideas?

Fenloh

joshuha
October 18th, 2008, 19:31
You are trying to make it so a player can check of a Use Edge type checkbox and apply the Shadowrun rules right? I have something like this already written if you want I can give you the code so you can see how I did it.

Fenloh
October 18th, 2008, 19:36
that would be great!

joshuha
October 18th, 2008, 20:10
Actually looking at the code I didn't have edge done yet heh. I was working on a SR4 ruleset with sloejack who has been MIA for awhile. Devin worked on some graphics and I am sure I could get his permission for a release but not sure about sloejack as he did the work on the character sheet. Give me a day or two to see if I can contact him for permission.

If he doesn't I will extract out the portion I have done which include converting the modifier box to a Pool rolling that automatically calculates hits and gltiches (and critical glitches). It would not be too hard to add a check box for edge there for exploding dice.

Fenloh
October 18th, 2008, 21:07
the rolls are already done as is the sheet. Glitches, Crits and some oder stuff too.

I am working on some "features" now. Edge use for checks, Combattracker, NPCs and such. Well the Combattracker is quite tricky, but eventually i will understand it and master that also.

the exploding of the Dice works fine, i just need to get the comparison worked out, so that all the "explosion" rolls will be rolled.

Fenloh

joshuha
October 18th, 2008, 21:50
Well I did get permission to release it so I will zip it up and have it posted soon. If anything it may give some ideas.

As far as the explosions, I can give some hints how I have done it in the past. Traditonally if you use throwDice to throw more dice but still exit the function normally you get multiple sets of die result on the screen and this can look ugly and make things difficult to figure out. What I have done in the past is examine the results list and look for any max die. Then I save the current results to the registry, throw the new exploded die and then exit the function returning true to STOP processing. The beginning of the onDiceLanded checks for values in the save dice results list and if so takes those and adds the new incoming exploded dice results to form a result list and then repeat the process until no max dice come up. Then you can continue processing as normal and display the final results list.

What this enables is all the dice on the screen to still be graphical thrown and take the actual results (without resort to rand() functions) but still show the output as one final roll to make calculating totals, success, glitches, etc. easier.

Fenloh
October 19th, 2008, 05:10
Ui, Very nice! Ill look into it asap.

Fenloh