PDA

View Full Version : Problems passing node information through OOB message



Diablobob
April 17th, 2019, 06:12
I was having issues with OOB messages.

description of situation: in the character sheet, I am trying to change a value. Changing that value triggers a script to create a child, save the value of field2 to the child node, and then update field2.

Obviously to create a child, you need to be host.

when I pass the node of the charsheet through the msgOOB, everything goes in right... verified with debug statements... but when I pull the info out in the triggered function, the node is nil...

UPDATE: continued from explanation above: so I use x.getNodeName() to turn the node name into a string. I then send the string through the OOB message. Then I have the GM pull the string, and turn it back into the node using DB.findNode(x) Then I have the GM use that correct node to run the original function again.

LESSONS LEARNED: OOB messages can transfer some nodes, but not all. And the ones it can, seam to be inconsistent. So turning it into a string and sending that, is a very stable way to perform this function so that the player can initiate the GM to process a function for them (inside FG).

CORRECTED AND WORKING CODE:

my XML code for the trigger:


function onValueChanged()
local nodeWin = window.getDatabaseNode();
DoStuffManager.sendFunction(nodeWin);
end;



my LUA code:


function onInit()
OOBManager.registerOOBMsgHandler(RUN_FUNCTION, runFunction);
end


send code function: (to see if the Host is running the script, if not send OOB message, if host run the rest of the code)


function sendFunction(nodeWin)
if not User.isHost() then
Debug.console(nodeWin);
local CharShtNm = nodeWin.getNodeName();
Debug.console(CharShtNm);
local msgSCT = {};
msgSCT.type = RUN_FUNCTION;
msgSCT.CharShtNm = CharShtNm;
Debug.console(msgSCT);
Comm.deliverOOBMessage(msgSCT);
return;
end
Debug.console("yay, made it!");
REST OF CODE!
end


Then I pull data in the OOB triggered function: (have the host turn the OOB string sent back into a node, and then have the host run the sendFunction using the correct node)


function runFunction(msgSCT)
Debug.console("doing stuff");
if not User.isHost() then
return;
end
local CharShtNm = msgSCT.CharShtNm;
Debug.console(CharShtNm);
local nodeWin = DB.findNode(CharShtNm);
sendFunction(nodeWin);
end


This is the corrected code... I figured out with your guys’s Help that OOB messaging should mainly send string data, and find the node in the other side... that’s the only reliable way to use it... things like nodeCT and such being transferred, is dependent on too many things to be truly reliable as a method to trigger the functions.

I also figured I’d post what I learned, so others could get some help from it as well!

damned
April 17th, 2019, 06:51
first part to test

msgSCT.type = CREATE_NODE;
i think should be
msgSCT.type = RUN_FUNCTION;

in your example?

Diablobob
April 17th, 2019, 12:12
It is, I just edited the name of the message to try not to make it confusing... I’ve gone through many stages of troubleshooting... after I posted the question, I changed it in to meet the post for ease of problem solving. Good catch! But unfortunately that is not my issue... I wish it was... the output is the same...

Diablobob
April 17th, 2019, 12:21
What is the function to find a node using it’s name?

Would it work with getCTNode?

Trenloe
April 17th, 2019, 13:16
I think you’re on this track now - You need to pass the complete node name as a string to the OOB process, and then get the node from that on the other side.

Use <databasenode>.getNodeName to get the complete node name as a string: https://www.fantasygrounds.com/refdoc/databasenode.xcp#getNodeName

Use DB.findNode to get the databasenode object from the node name: https://www.fantasygrounds.com/refdoc/DB.xcp#findNode

Diablobob
April 18th, 2019, 03:12
Thank you, wonderful guys, for the help!

damned
April 18th, 2019, 05:43
Thank you, wonderful guys, for the help!

Nah - you have to post your working code for the next person...!

Diablobob
April 18th, 2019, 11:02
I did. I edited the original posted code, to be the current and working code.

I figured that’d Be less confusing than having multiple versions, only one that worked.

I also updated that post to try to better explain what’s going on and the thought process behind it.

Please let me know what you think, and if I missed anything.

Thank you again!