PDA

View Full Version : need coding help with BOTTOMs and how to reference another window



grelgen
February 16th, 2016, 05:07
As the title says, Im missing something basic and my infamiliarity with the environment has me flustered. I do a little bit too much HTML coding and i may be confusing the DOM there with the way FG works. Im working on a CORErpg extension to make a Roll&Keep window.

First, how do I reference data from another window? My new window will need to pull data off of the charactersheet. Stuff like 'name' and ability scores. So far, alls I've gotten is nil references trying to use stuff like parent and windowlist. What's the correct way to go about it?

Second, here is my code to put two number boxes at the bottom of a window.


<template name="rnk_close">
<buttoncontrol>
<anchored height="24" width="24" />
<icon normal="rnk_button_close" pressed="rnk_button_close_down" hover="rnk_button_close_hover" />
<script>
function onButtonPress()
window.close();
end
</script>
</buttoncontrol>
</template>
<template name="close_rnk">
<rnk_close>
<anchored>
<top offset="0" />
<right offset="0" />
</anchored>
</rnk_close>
</template>
<template name="rnk_number">
<numberfield>
<anchored height="20" width="30" />
<noreset />
<script file="common/scripts/number.lua" />
</numberfield>
</template>
<template name="simple_rnk_number">
<rnk_number>
<droptypes>
<type>number</type>
</droptypes>
<font>sheetnumber</font>
</rnk_number>
</template>
<template name="sheet_rnk_number">
<simple_rnk_number>
<frame mergerule="replace" name="fielddark" offset="7,5,7,5" />
<stateframe>
<keyedit name="fieldfocus" offset="7,5,7,5" />
<hover name="fieldfocus" offset="7,5,7,5" hidereadonly="true" />
<drophilight name="fieldfocus" offset="7,5,7,5" hidereadonly="true" />
</stateframe>
</simple_rnk_number>
</template>
<windowclass name="rnkwindow">
<frame>fielddark</frame>
<sheetdata>
<close_rnk />
<sheet_rnk_number name="roll_entry">
<anchored>
<left offset="50" />
<bottom offest="-10"/>
</anchored>
</sheet_rnk_number>
<sheet_rnk_number name="keep_entry">
<anchored>
<bottom offest="-10"/>
<left offset="130" />
</anchored>
</sheet_rnk_number>
</sheetdata>
</windowclass>


That code puts the close button correctly centered on the top right corner. I can even move it by putting in numbers other than 0. But the number boxes refuse to get off the bottom row. I can move them side to side, but any number i put for the bottom offset has no effect. What am I doing wrong there?

Trenloe
February 16th, 2016, 05:21
1) If the window you want to reference is a completely separate window, then you're best off going directly to the data the window displays in the database. Even if the data is on another tab of a window (e.g. a character sheet) it usually is best to go the database as well. Some info on the FG database here: https://www.fantasygrounds.com/modguide/database.xcp

2) Have you tried a bottom offset of -50 just to see if that gets the control off the bottom of the window? I don't know what the dimensions of the fielddark frame are, but using <anchored> without a <parent> results in the windows edge being used as the reference. See the "Anchoring" section here: https://www.fantasygrounds.com/modguide/windowing.xcp How large is the frame used for the window?

Trenloe
February 16th, 2016, 05:26
To expand on point 1 - the CoreRPG ruleset uses a lot of code that refers to the "actor" - this is a reference to a PC or NPC record. scripts\manager_actor.lua has a few functions to get the actor record (rActor) and then use rActor to access further data - and it also is used to get a databasenode (https://www.fantasygrounds.com/refdoc/databasenode.xcp)reference so you can extract specific data from the character record in the database. This is really the best way to go. If you haven't looked at the FG database and how to access data there it can be a bit daunting, but it's well worth spending the time to get to know your way around it.

grelgen
February 16th, 2016, 05:56
problem 2 was fixed with


<anchored>
<top anchor="bottom" offset="-20"/>
<left offset="10" />
</anchored>

grelgen
February 16th, 2016, 06:07
hrm, how do i call?

my code line is:
desc = getActor("pc","databasenode").window["name"].getValue() + "test";

im getting error:
Runtime Notice: Reloading ruleset
Script Error: [string ""]:1: attempt to call global 'getActor' (a nil value)

Trenloe
February 16th, 2016, 06:20
manager_actor.lua is a global script package - which is defined in base.xml. See the "Script Packages" section here: https://www.fantasygrounds.com/modguide/scripting.xcp

The CoreRPG base.xml file has the following code: <script name="ActorManager" file="scripts/manager_actor.lua" /> This defines the global package as ActorManager. Therefore, you can call getActor with ActorManager.getActor...

Trenloe
February 16th, 2016, 06:41
Your biggest "problem" could be deciding on which character record to access, as a player could own multiple characters and have multiple character sheets open. Which one do you access?

FG has a useful function for this - CombatManager.getCurrentUserCT(). This is in scripts\manager_combat.lua and returns the combat tracker node for either the currently active PC or NPC (useful for the GM, but also for a player with multiple PCs) or the currently active character sheet for a player. The CTNode can be used to get the rActor record: ActorManager.getActorFromCT(CombatManager.getCurre ntUserCT());

This is heavily linked to the combat tracker, which might not always be appropriate, so you might just want to go for the currently active PC for a player, and use something like this: rActor = ManagerActor.getActor("string", "charsheet." .. User.getCurrentIdentity()); However, this won't work for the GM.

See here for info on activating a character: https://www.fantasygrounds.com/wiki/index.php/Character_List

grelgen
February 17th, 2016, 00:01
its for a 7th sea campaign. the combat tracker they use is really wonky and doesnt fit easily into the existing initiative based combat tracker FG uses.

so if getActor() is DB wide, and the DB includes all players and npcs, then getting to the right player might be player driven via a combo box... or ill need to be more inventive. wait, getActor() only has 2 arguments... why does your example include that User bit?

Once i can see how the DB is laid out once it's all running, it should be a snap... catch 22 is getting it all runnning, lol

Trenloe
February 17th, 2016, 00:08
wait, getActor() only has 2 arguments... why does your example include that User bit?
rActor = ManagerActor.getActor("string", "charsheet." .. User.getCurrentIdentity()) has two arguments. Two dots: ".." in LUA is a concatenation - so "charsheet." .. User.getCurrentIdentity() is a single argument.

The advantage of this command is that, on the player side, it will use whichever PC is activated - the last one they selected from the PC portraits in the top left of the desktop. See here for info on this: https://www.fantasygrounds.com/wiki/index.php/Character_List

Using the active character would replace any combo box you might be thinking about (it's doing the same job).

grelgen
February 17th, 2016, 01:20
this is just getting frustrating... how do i look at this in FG as a player, not a GM. cause this is just impossible to test otherwise

leozelig
February 17th, 2016, 01:36
Load the campaign like you usually do as the GM. Then, fire up another instance of FG, and click 'Join Game'. For the host address, enter 'localhost' - you can enter whatever you want for a username. You should have two windows showing FG desktops, one as the GM/host and one as a player/client.

13055

Trenloe
February 17th, 2016, 01:41
this is just getting frustrating... how do i look at this in FG as a player, not a GM. cause this is just impossible to test otherwise
Start another instance of FG on the same computer and "Join Game" with a server address of localhost