PDA

View Full Version : I don't think I understand tostring()



darrenan
June 17th, 2024, 18:26
I'm building a new ruleset and use tostring() all over the place, and up until today, without any issues. Today, in one of my new scripts I'm suddenly getting this:

61088

The script in question is running in the client, and is part of a callback function invoked by user.requestIdentity, if that matters. Here is the script, the error occurs in the first line of requestResponse:



--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--

--
-- GLOBAL DEBUG WRAPPERS
--

local sScope = "playbook";
function debugFormatted(sFormat, ...)
GlobalDebug.debugFormattedScope(sFormat, sScope, ...);
end

function onInit()
GlobalDebug.registerGlobalDebugScope(sScope);
end

function onCreate()
if Session.IsHost then
local node = DB.createChild("charsheet");
requestResponse(true, node.getName());
else
if not bRequested then
User.requestIdentity(nil, nil, nil, nil, requestResponse);
bRequested = true;
end
end
parentcontrol.window.close();
end

function requestResponse(result, identity)
sResult = tostring(result);
debugFormatted("requestResponse: result=%s identity=%s", sResult, identity);

local node = DB.findNode("charsheet." .. identity);
local w = Interface.openWindow("charsheet", node.getNodeName());
if w then
nodePlaybook = getDatabaseNode();
if nodePlaybook then
w.initialize(nodePlaybook);
else
debugFormatted("onCreate: getDatabaseNode() returned nil");
end

if w.overview.subwindow.name then
w.overview.subwindow.name.setFocus();
end
end
end


And here is where that script is used:



<windowclass name="playbook" copy="record_window">
<gmexport>playbook</gmexport>
</windowclass>

<windowclass name="playbook_header" copy="record_header">
<script file="campaign/scripts/playbook.lua" />
<sheetdata>


I thought that tostring() was just part of the base lua language, am I wrong about that? Is there some reason it doesn't work on the client side? Confused. Any help appreciated.

darrenan
June 17th, 2024, 18:33
ok, I don't think this is about tostring() specifically, but rather host vs. client capabilities. If I comment out that line and the reference to sResult, I get a similar error about "DB" two lines down. Is there a list of things that are unusable on the client side?

superteddy57
June 17th, 2024, 18:36
Basically anything that the player doesn't own. You would need to use OOBManager to set up a way for the player to push things to the host to run and change things if it's outside of that ownership.

superteddy57
June 17th, 2024, 18:38
An example can be seen with the 5e Character Wizard as it creates a new character sheet either on the host or through the player side. The commit code checks which is making the request and handles it differently based on who is requesting the commit.

darrenan
June 17th, 2024, 18:40
Basically anything that the player doesn't own. You would need to use OOBManager to set up a way for the player to push things to the host to run and change things if it's outside of that ownership.

So you're saying that the DB. package cannot be used at all the client side? Because that's the error I'm getting:

61089

darrenan
June 17th, 2024, 18:43
Basically anything that the player doesn't own. You would need to use OOBManager to set up a way for the player to push things to the host to run and change things if it's outside of that ownership.

also, I thought the whole point of User.requestIdentity (https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644683/User) was to send a message to the host to create a new identity and then send the result back to the client. Is that not the case? From the wiki:


Send a request to activate the given identity to the host. The request may fail if the identity is already in use or owned by another user.

superteddy57
June 17th, 2024, 18:53
I was responding your question related to what the host vs. player can do from within the code. My example (5e > charwizard > scripts > manager_charwizard.lua line 1169) shows (what it looks like you are trying to do) how it creates new characters. I'm a bit confused on why you are trying to make your boolean to a string. The code can run the global DB API from the player side, it just can't use some of the functions if it attempts to change anything within the database. It can collect data. So some will work and some won't from the player side.

darrenan
June 17th, 2024, 18:56
I was converting the bool to a string as part of a debugging output statement, which is irrelevant now that I see that I can't reference the DB package either (did you look at the error I included three posts above?). It's almost like the requestResponse function is running in some kind of constrained scope that doesn't have access to any of the usual APIs.

Trenloe
June 17th, 2024, 18:57
This is working fine on the player side in the PFRPG2 ruleset when creating an eidolon for a summoner PC - using virtually the same code you're using @darrenan. Let me investigate why the PFRPG2 code is working and yours isn't.

darrenan
June 17th, 2024, 18:57
I was converting the bool to a string as part of a debugging output statement, which is irrelevant now that I see that I can't reference the DB package either (did you look at the error I included three posts above?). It seems like the requestResponse function is running in some kind of constrained scope that doesn't have access to any of the usual APIs (because the error says that DB is nil).

darrenan
June 17th, 2024, 18:59
This is working fine on the player side in the PFRPG2 ruleset when creating an eidolon for a summoner PC - using virtually the same code you're using @darrenan. Let me investigate why the PFRPG2 code is working and yours isn't. I think the documentation regarding the second and third parameters may be a bit misleading...

Thanks. I've tried setting those parameters to "charsheet" and "name" as most of the examples I see are doing. It makes no difference. The big thing here that's different from other rulesets is that character creation is being triggered via a button on a record window, rather than from the typical charselect_client window. But I wouldn't think that would make any difference.

darrenan
June 17th, 2024, 19:05
I wonder if I should move this code to a global script block and call that from the onCreate function? Is the issue that this whole script block is attached to a windowclass?

darrenan
June 17th, 2024, 19:15
Yeah, moving the code in onCreate and requestResponse into my global CharacterManager script seems to have made the issue go away. I would be curious if anyone can explain why, but I think I'm unblocked now.

Trenloe
June 17th, 2024, 19:15
I wonder if I should move this code to a global script block and call that from the onCreate function? Is the issue that this whole script block is attached to a windowclass?
I think that's worth a test as the PFRPG2 code which is pretty much identical to your code is working and that's within a global script package. Maybe the script scope is different when running within a windowclass.

damned
June 18th, 2024, 00:03
So you're saying that the DB. package cannot be used at all the client side? Because that's the error I'm getting:

61089

The DB stuff can totally be used by players but anything that writes to the DB requires permissions.
Players only own their own charsheet and any notes they create. So they can write to these but not to other records.
To write to other records you have to use OOBM which then writes as the GM.

Probably nothing new in here to you - just responding to your question in case you were still unsure.

Trenloe
June 18th, 2024, 01:33
Yeah, moving the code in onCreate and requestResponse into my global CharacterManager script seems to have made the issue go away. I would be curious if anyone can explain why, but I think I'm unblocked now.
I think the issue is due to the parentcontrol.window.close() command which will close the script scope container where your code is running? As User.requestIdentity is asynschronous, the onCreate function code will continue and close the window, which I assume will close the container for the code, which will lead to unexpected results.

darrenan
June 18th, 2024, 23:35
duh, I didn't think of that but you're absolutely right. <facepalm/>