PDA

View Full Version : [Programming] windowlist within windowlist object



pr6i6e6st
September 22nd, 2019, 06:00
Hey again guys! this one i imagine is fairly simple to answer, it's just a simple syntax thing i'm having trouble with, i'm sure.

so in my ruleset, vehicles have windowlists that hold inventory like a character.

the PC sheets also have a windowlist that can hold vehicles like inventory.

example of what i want to do:
the weapons section of the PC sheets shows weapons from the inventory. instead of seeing weight, we see a field for damage and bonus.
29123
so basically what i would like is to have the armaments windowlist on the main page to contain all the armaments within the vehicles windowlist on the inventory page.

i'm sure it's something like what i have below with the setDatabaseNode() function, but i really am not sure how to delve further into the character sheet.

so i want the armaments windowlist from the mainsheet. . . .



<windowclass name="charsheet_main2" source="charsheet_main2">
<margins control="0,0,0,3" />
<sheetdata>
<windowlist name="armamentslist">
<anchored to="armamentsframe">
<top offset="40" />
<left offset="15" />
<right offset="-10" />
<bottom offset="-15" />
</anchored>
<child></child>
<child><backcolor>1A40301E</backcolor></child>
<datasource>.armamentslist</datasource>
<class>vehicle_armaments</class>
<acceptdrop>
<class>referencetext</class>
<class>referencetextwide</class>
<field>*</field>
</acceptdrop>
<allowdelete />
<script>
function onListChanged()

setDatabaseNode(DB.getPath(node, "*.vehicleinv"));
end
</script>
</windowlist>


. . . to have the same list of items as the vehicles in the list on the record_char_inventory.xml. . .



<windowlist name="vehiclelist">
<anchored to="vehicleframe">
<top offset="40" />
<left offset="15" />
<right offset="-10" />
<bottom offset="-15" />
</anchored>
<child></child>
<child><backcolor>1A40301E</backcolor></child>
<datasource>.vehiclelist</datasource>
<class>char_vehicle</class>
<acceptdrop>
<class>vehicle</class>
<class>referencetextwide</class>
<field>*</field>
</acceptdrop>
<allowdelete />
</windowlist>



the armaments list in the vehicles windowclass is in the record_vehicle.xml. . .


<windowlist name="armamentslist">
<anchored height="80">
<top parent="columnanchor" anchor="bottom" relation="relative" offset="10" />
<left offset="90" />
<right offset="-10" />
</anchored>
<frame>fielddark</frame>
<child></child>
<child><backcolor>1A40301E</backcolor></child>
<datasource>.vehicleinv</datasource>
<class>vehicle_armaments</class>
<acceptdrop>
<class>referencetext</class>
<class>referencetextwide</class>
<field>*</field>
</acceptdrop>
<allowdelete />
</windowlist>

Trenloe
September 22nd, 2019, 06:39
The <datasource> tag determines the database location of the data displayed in the windowlist.

pr6i6e6st
September 22nd, 2019, 06:44
So for the armaments section of the main page, would I set it like


<datasource>.vehiclelist.window.vehicleinv</datasource>

pr6i6e6st
September 22nd, 2019, 07:30
so i tried setting the <datasource> tag for the vehicle inventory and the player armaments list to <datasource>DB.VehicleInv</datasource> and that almost worked, but then each vehicle in the list had the same armaments. i guess setting it to DB.whatever gave no room for variance? not what you said to do anyway, but i thought i'd see how it worked. i don't want all the vehicles in the inventory to have the same armaments, but i do want the armaments list on the PC sheet to have all the armaments from the vehicle's inventory. would a DB.addHandler() and a getWindows() function be better? something like how encumbrance is updated when item weight is changed?

edit: i suppose this could work for now if i limited the vehicle list to one vehicle only.

this is how the source looks in the db.xml file, so do i want my datasource to look something like <datasource>.vehicle.vehiclelist.VehicleInv</database>? i'm missing something there if so.



<vehicle>
<id-00006>
<vehiclelist>
<VehicleInv>
<id-00002>
<cost type="string">$300</cost>
<isidentified type="number">1</isidentified>
<itemtype type="number">2</itemtype>
<locked type="number">1</locked>
<name type="string">.357 Magnum Revolver</name>
<notes type="formattedtext">
<p>Bonus: +1</p>
<p>Damage: 2</p>
<p>Range: Medium</p>
<p>A classic high caliber revolver, equally popular amongst both Frontier marshals and lowlifes.</p>
</notes>
<weaponbonus type="number">1</weaponbonus>
<weapondamage type="number">2</weapondamage>
<weaponrange type="number">3</weaponrange>
<weight type="number">1</weight>
</id-00002>
</VehicleInv>
</vehiclelist>
</id-00006>
</vehicle>

pr6i6e6st
September 23rd, 2019, 06:16
ok, so i have to be close here, because when i entered the following as the datasource, it removed what was in the vehiclelist on the players inventory page.
<datasource>.*..VehicleInv</datasource>

but it still doesn't show any of the inventory from the vehicle in the players main sheet.

the datasource of the vehiclelist is:
<datasource>.vehiclelist</datasource>

while the datasource of the vehicles own inventory is:
<datasource>.VehicleInv</datasource>

Moon Wizard
September 23rd, 2019, 08:19
* doesn’t work for control data source. It’s only for DB.addHandler/removeHandler.

You have to have a specific path to a set and f child nodes to use data source directly.

Otherwise, you’re better off rolling your own that queries existing records across all sources, builds each window in the list, then adds handlers for onAdd/onDelete to add/remove windows. This is how the campaign record master lists are built.

In general that’s much more complex, and I recommend against using lists fed from multiple locations.

Regards,
JPG

pr6i6e6st
September 23rd, 2019, 17:53
* doesn’t work for control data source. It’s only for DB.addHandler/removeHandler.

You have to have a specific path to a set and f child nodes to use data source directly.

Otherwise, you’re better off rolling your own that queries existing records across all sources, builds each window in the list, then adds handlers for onAdd/onDelete to add/remove windows. This is how the campaign record master lists are built.

In general that’s much more complex, and I recommend against using lists fed from multiple locations.

Regards,
JPG

Ok, so I'm limited to a single data source then unless I get crazy with the code.

So perhaps there's something I can do to be able to ”equip” a vehicle, setting that particular vehicles inventory as the new data source to use. So rather than getting all the different .VehicleInv from the different vehicles in the inventory, we just get the one list from the equipped vehicle.

Or I could just make the vehiclelist entries have subwindows with their .VehicleInv list below each entry.

Moon Wizard
September 23rd, 2019, 18:27
You can use windowlistcontrol.setDatabaseNode to update the source node for the windowlist. Technically, the windowlist does support a table of node paths, or a single node path. However, it does not support wildcards, so you still have to be specific.

JPG

pr6i6e6st
September 23rd, 2019, 18:58
Ok, so say the windowlist entry of the vehicle list has a button much like the ”carried” button, but it's only equipped or not equipped.

What I want then, is to have a code in that equipped button, when set to equipped, to tell the armaments windowlist in the player sheet, to have the same data source as the equipped vehicle’s .VehicleInv?

So something like

onValueChanged()
if getValue() ==1 then
NewNode = window.getDatabaseNode().getChild(”.VehicleInv”)

Windowlist.getDatabaseNode().getChild(”.armaments” ).setDatabaseNode(NewNode)

Moon Wizard
September 23rd, 2019, 22:36
You're getting into some pretty advanced stuff, because you're trying to link multiple records into a view within another record. That's going to be complicated, and require quite a bit of work.

As for your specific mention above; windowlist.setDatabaseNode is only for the windowlist control itself. You can't switch back and forth between controls and database nodes. Once you go to database nodes, you don't know which controls are viewing that database node. You can only go from windowcontrol->databasenode, not the other way.

Also, are you saving the equipped status of the vehicle somewhere? It seems like it would need to be saved with the character record as a specific character vehicle record, not as part of the original vehicle record. In this case, it gets even more complicated, because you basically need a local character vehicle record that stores specific character vehicle information (equipped, etc.) as well as storing the main vehicle record database information. Then, since each window can only have one data source, you would have to create a window with the character specific vehicle information as controls, and use a subwindow control and subwindow.setValue API to make any vehicle specific information appear (name, etc.). Like I said, it starts getting very complex going across records.

In the equipped button, you would add something like:

In button code:



function onButtonPress()
if getValue() == 1 then
window.setEquippedVehicle();
else
window.unequipAllVehicles();
end
end


In vehicle window containing button:



function setEquippedVehicle()
windowlist.setEquippedVehicle(self);
end

function unequipAllVehicles()
windowlist.setEquippedVehicle(nil);
end


In the vehicle list control containing the vehicle windows with the buttons:



function setEquippedVehicle(winVehicle)
foreach _,w in ipairs(getWindows())
if w ~= winVehicle then
w.equipped_button.setValue(0);
end
end
end


Regards,
JPG

pr6i6e6st
September 23rd, 2019, 23:10
Ok, thank you very much for your time. Ill play around with this for the next couple of days and see if i cant work something out. Im having a hard time finding much else i need to do to my ruleset to make it even more convenient for players and gm anyway.

I have just been speculating since this morning, not actually working at the code, but I'll try adding the new ”equipped” button to the player record.

And yes, I believe the vehicle record is being saved as a new record within the player sheet, as it's not bound to the original record

Thanks again, I'll be back if I don't figure it out/give up lol

pr6i6e6st
September 24th, 2019, 22:32
Regards,
JPG

alright. so instead of a list devoted entirely to all armaments in possession of the vehicles owned, i merely added the armaments list to the window of the vechicle. so now there is a windowlist within a windowlist entry. It actually looks a lot better than i was thinking originally.

so now i have another quandary. when rolling an attack with these armaments, you add your ranged combat skill, your base attribute, the armament bonus, and any modifiers.
now, i've been successful with making the thrusters from the vehicle itself add all of that to make a roll from the thrusters field in the vehicle windowlist entry on the character sheet. but when i go a step further, and try to get the armament (which is within the vehicle inventory list, which is within the vehicle within the vehicle list entry on the character sheet) to roll in a similar method, it's failing to index the stats i get it to look for.

so this is what is in the Thrusters for the windowlist entry. and i basically want the same thing (rngcomnum instead of pilotnum, though)
29146



<script>
function onInit()
CombatSkill = "pilotnum.slot.amount";
CombatBase = "charagilnum.slot.amount";
CombatName = "Pilot Action"

nBaseTotal = window.getDatabaseNode().getChild("..." .. CombatSkill .. "").getValue() + window.getDatabaseNode().getChild("..." .. CombatBase .. "").getValue() + getValue() + ModifierStack.getSum();
nStress = window.getDatabaseNode().getChild("...stressroll.slot.amount").getValue();
end
function onDragStart(button, x, y, dragdata)
onInit();
local StateTime = CalendarManager.getCurrentTimeString();
local WeaponName = window.name.getValue();
local description = "" .. StateTime .. ": " .. WeaponName .. ": " .. CombatName .. ": "
local nValue = getValue();
local aDice, nMod = StringManager.convertStringToDice(nTotal);
local Negate = 0;


local bDescNotEmpty = true;


if nStress > 0 then
for i=1,nStress do
table.insert(aDice, "dS");
end
end
if nBaseTotal > 0 then
for i=1,nBaseTotal do
table.insert(aDice, "dB");
end
else
for i=1,-nBaseTotal do
table.remove(aDice);
end
end
dragdata.setType("dice");
dragdata.setDieList(aDice);
dragdata.setDescription("" .. StateTime .. ": " .. WeaponName .. ": " .. CombatName .. ": ");
dragdata.setStringData("" .. StateTime .. ": " .. WeaponName .. ": " .. CombatName .. ": ");
return true;
end

function onDoubleClick(x, y)
onInit();
local StateTime = CalendarManager.getCurrentTimeString();
local WeaponName = window.name.getValue();
local description = "" .. StateTime .. ": " .. WeaponName .. ": " .. CombatName .. ": "
local aDice, nMod = StringManager.convertStringToDice(nTotal);
local Negate = 0;

if nStress > 0 then
for i=1,nStress do
table.insert(aDice, "dS");
end
end

if nBaseTotal > 0 then
for i=1,nBaseTotal do
table.insert(aDice, "dB");
end
else
for i=1,-nBaseTotal do
table.remove(aDice);
end
end
Comm.throwDice( "dice", aDice, Negate, description)
end

function onValueChanged()
onUpdate();
end
function onUpdate()
end
</script>

Moon Wizard
September 24th, 2019, 23:50
Looking at your script, I don't see where "nTotal" variable is getting set. It is used in "local aDice, nMod = StringManager.convertStringToDice(nTotal);", but it looks like it's not getting initialized.

Make sure to liberally use Debug.chat commands to output all the variables for inspection when you are having trouble figuring out what's not working with a script.

Regards,
JPG

pr6i6e6st
September 25th, 2019, 06:55
Looking at your script, I don't see where "nTotal" variable is getting set. It is used in "local aDice, nMod = StringManager.convertStringToDice(nTotal);", but it looks like it's not getting initialized.

Make sure to liberally use Debug.chat commands to output all the variables for inspection when you are having trouble figuring out what's not working with a script.

Regards,
JPG

i believe that's probably a remnant of a code i used as a template, but it doesn't appear to have much of an effect. I got it working so that you can doubleclick the bonus box of the armament that is in your vehicle in your inventory. and if it's not in there, it gives a message in the chat that rolls need to be made from the character sheet.

but i can't get the dragdata to go back down the pipeline. i used something similar to what you explained earlier with the equipped button in order to send a throwdice command on the character sheet with all the appropriate data. but i'm not sure how to return the dragdata, seeing as the pointer is in this twisted little windowlist-entry-windowlist-entry and we're getting dragdata/draginfo from the character sheet.