PDA

View Full Version : Using a wildcard in a function



Visvalor
December 12th, 2009, 23:25
I'm trying to set up a sort of tabs inside of a charsheet in a window and the easiest way I know how to do this is by setVisible function and just hiding windows.

Now the problem is that it only hides the window the stuff is mounted to not the individual strings and number controls inside of it, so I need to set a setVisible for each one of those with the onClick function of the "tab" button to hide things.

My question is can I set things up to wildcard or something where it will hide EVERYTHING mounted to a generic control by naming for example say the generic control is named charsheet_skills1 and I name everything on this sheet like hiding to charsheet_skills1-1 and sneaking charsheet_skills1-2 etc and can I wildcard somehow

<script>
function onClickDown(button, x, y)
window.charsheet_skills1.setVisible(true);
window.charsheet_skills1*.setVisible(true);
bringToFront();
end
</script>

Where the charsheet_skills1 and everything with that in it gets hidden at the same time so I don't have to type up 40+ things per tabbed page to hide =P?

Brenn
December 13th, 2009, 02:28
You could store the created windows in a table then index through the table to adjust the visibility of the windows.

Visvalor
December 13th, 2009, 02:30
Sorry I'm a copy-pasta noob you'll have to explain how that works =)

tdewitt274
December 13th, 2009, 04:12
I think he's referring to the Lua language for:

Tables (https://lua-users.org/wiki/TablesTutorial)
and
For loops (https://lua-users.org/wiki/ForTutorial)

To result in something like:


for key,value in pairs(t) do
print(key,value)
end


I've seen stuff like the above code all over the 4E_JPG, but don't understand it yet. The Lua Tutorials (https://lua-users.org/wiki/TutorialDirectory) are pretty basic, but it'll give you the idea of what you're working with.

Brenn
December 13th, 2009, 05:29
I think he's referring to the Lua language for:

Tables (https://lua-users.org/wiki/TablesTutorial)
and
For loops (https://lua-users.org/wiki/ForTutorial)

To result in something like:


for key,value in pairs(t) do
print(key,value)
end

I've seen stuff like the above code all over the 4E_JPG, but don't understand it yet. The Lua Tutorials (https://lua-users.org/wiki/TutorialDirectory) are pretty basic, but it'll give you the idea of what you're working with.

That's exactly what I'm talking about. You can create the windows in script and when you do instead of assigning them to individual variables put them in a table. You then have a table that has pointers to all of the windows in question and can use the lua structure:



for i, v in pairs(myWindowTable) do
v.setVisible(true);
end


That would iterate through each window and make it visible.

Foen
December 13th, 2009, 06:32
The other thing would be to use subwindows, these contain controls and when visible all the inner controls are visible and when hidden all the inner controls are hidden.

That is how the charsheet, npc sheet and item sheet tabs work.

Typically you would have a windowclass definition for the contents of each tab, then include it in the main window using a subwindow control. Subwindows are activated (instead of shown/hidden), and you can read more about them in the FG reference documentation (https://www.fantasygrounds.com/refdoc/).

Visvalor
December 13th, 2009, 08:11
Yes the ideal thing would be a set of subwindows... but I'm having a hard time getting it around my head.

Also the way I have it setup is a generic control with a large generic control to the right and 10 little ones on the left I use as buttons.

If anyone has an example I can look at (I'm a learn through example type of guy) that would be great =)

Brenn
December 13th, 2009, 15:43
If anyone has an example I can look at (I'm a learn through example type of guy) that would be great =)

To see an example of what Foen is talking about run d20unpack.exe in you FG program directory (the ruleset will be extracted to examples in the application data folder) and then look at the character sheet code. The tabbed character sheet is the best example that I can think of in the stock stuff.

Visvalor
December 13th, 2009, 17:58
Yea I've looked over the tabs and tried to get it working inside of a character sheet, but it always returns a nil value =p

I'm still using the setVisible method , I'd like to know better how to do the tables at it seems like it would work well and that would be good to see in practice. Know where I'd find a functioning way to do the tables thing I could look at :P?

Visvalor
December 13th, 2009, 18:35
Ok is there a way I can put things into a group?

Like a group="charsheet_rogue_skills" and then set the group.charsheet_rogue_skills.setVisible(false);

Is there a way I can do that?

Foen
December 13th, 2009, 19:19
Nope, no such way (it is on the wish list).

I think you are going to have to look long and hard at subwindows: they are a bit scary, but they do just what you want.

Foen

Visvalor
December 13th, 2009, 20:07
Ok well I'm looking into it, do I need the tabcontrol.lua stuff to work with subwindows?

Looking at this;
<subwindow name="inventory">
<bounds>0,0,-1,-1</bounds>
<class>charsheet_inventory</class>
</subwindow>

It's in my charsheet toplevel folder, can I put something like that inside say charsheet_inventory and have it bound to be in the middle of that page, and would it go away when tabbing away from that page?

Also other questions is how do I even set it up...

<subwindow name="potions">
<bounds>25,25,200,200</bounds>
<class>potion_sheet</class>
</subwindow>

Ok to make that above thing work, where would I define the class? In charsheet.xml?

Also do I pull it up with subwindow.potions.setVisible(true); with a generic control button?

Visvalor
December 13th, 2009, 20:40
Ok sooo this didn't work :P;


<subwindow name="test">
<bounds>0,0,-1,-1</bounds>
<class>charsheet_test</class>
</subwindow>

And I put this line into charsheet.xml


<includefile source="charsheet_test.xml" />

And I made a file called charsheet_test.xml and made it just a regular page, with a generic control in it. Then inside of the sheet charsheet_skills where I wanted to call this page I put;


function onClickDown(button, x, y)
subwindow.test.setVisible(true);


Ooook so all of that returned a nil value :P am I even shooting in the right ballpark?

Foen
December 13th, 2009, 21:06
You don't need tabcontrols to use subwindows, but you will need some way of setting them visible or invisible.

Some basic stuff about subwindows:

Subwindows embed one window within another, I'll call the embedded window the inner window and the main window the outer window.
Typically the outer window is created as normal, with a frame etc, such as the charsheet window which is defined as a windowclass called "charsheet" (in some rulesets it is in charsheet.xml, and in others it is in charsheet_toplevel.xml).
The inner window needs its own definition: which says what controls are in there, any layout or calculation logic etc. For example, the 'main' tab of a charsheet is defined as a windowclass called "charsheet_main" in charsheet_main.xml.
The subwindow control is *separate* from the subwindow it contains. It is a container control, and the inner window sits inside it.
To make a subwindow visible, call setVisible(true) on the subwindow control, and to hide it call setVisible(false) on the subwindow control.
A subwindow control can be declared to be visible at initialisation by including an <activate/> tag in the subwindow definition.

If you have created charsheet_test.xml which defines a new windowclass called charsheet_test (the inner window definition) and you include a subwindow control called "test" (like your code snippet above), then you should be able to show the subwindow using the call test.setVisible(true). If this is being run from inside another control (say a button on the sheet) rather than from the sheet itself, you may need to use window.test.setVisible(true).

Foen

Visvalor
December 13th, 2009, 21:27
O_o! It Worked!