Log in

View Full Version : User.requestIdentity - invoke host function



Xarxus
March 31st, 2024, 19:28
If I understand correctly how User.requestIdentity works, it is used when it is necessary to generate a record. From what I've seen, the idea behind its use is that the creation is always done by the host, I imagine to avoid the generation of duplicate IDs.

The behavior should be this:

Event
--> if Host --> record generation
--> if client --> generation request to the host with indication of the host function that must perform the activity. The host function receives two parameters indicating whether it succeeded in creating a new ID and the ID to use.

Did I get it right?

Assuming that I have understood correctly how the code should be organized if instead of creating a single record, the request must perform the creation of n records (perhaps with a loop)?
I imagine if the event occurs on the host there would be no problem, but what about the client? Should the client make the request to generate inside a loop? And what happens if for each record generated, other subrecords must be generated (a nested list)?

What I need to generate I have a structure like this:


<mylist1>
<id-00001>
... fields
<mylist2>
<id-00001>
... other fields
</id-00001>
<id-00002>
... other fields
</id-00002>
</mylist2>
</id-00001>
<id-00002>
... fields
<mylist2>
<id-00001>
... other fields
</id-00001>
</mylist2>
</id-00002>
<id-00003>
... fields
<mylist2>
<id-00001>
... other fields
</id-00001>
<id-00002>
... other fields
</id-00002>
<id-00003>
... other fields
</id-00003>
</mylist2>
</id-00003>
...
</mylist1>

I think it's simple to add an element to mylist2 using User.requestIdentity, just pass it the correct node (e.g.: node -_> mylist1.id00002.mylist2), but what if I wanted to add an element to mylist1 and inside it n elements to mylist2?

And what if I have to generate the entire mylist1 structure with all elements (id0001, id0002, etc.)?

Is there a way to invoke a function on the host, regardless of generating an ID? If that were the case, the host function would do the generation, so I wouldn't have to worry about duplicate IDs.

Moon Wizard
April 1st, 2024, 00:47
You should not use the User.requestIdentity for anything. It is purely a simple API to generate new character sheets, based on a few other settings.

If you want a Player client to send a request to the Host client to generate a record on a record not owned by the player, you should use a OOB message to send a request to the host, which the host can then use to add a new sub-record using the information in the OOB message. (For consistency, you can send the message on both Host and Player instances with a target of Host only; and the Host will handle either source.) There are many examples of that in the existing rulesets (in CoreRPG, it's used in DiceTowerManager, EffectManager, ItemManager, LanguageManager, and more.)

Regards,
JPG

Xarxus
April 2nd, 2024, 12:04
So, if the record is owned by the client, it can be generated directly?
Is there a function to get a new ID?

Trenloe
April 2nd, 2024, 13:25
Is there a function to get a new ID?
Are you referring to the database id-XXXXX intermediate node name? If so, use DB.createChild without a "type": https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB#createChild

Xarxus
April 2nd, 2024, 16:09
Yes, I am referring to id-xxxxx. If I don't specify the name, does createChild increase the id by itself?

Trenloe
April 2nd, 2024, 16:32
If I don't specify the name, does createChild increase the id by itself?
Yes (kinda): "If this parameter is omitted, a new unique node name will be generated." Usually it will increase the ID number, but if there is an earlier "space" then that may be used instead.

Xarxus
April 2nd, 2024, 19:15
That's good!

Ty