PDA

View Full Version : LUA, controls, and other 2.0 questions...



TarynWinterblade
April 27th, 2007, 07:38
I've been updating a few of the rulesets my group uses (read: completely redesigning from the ground up, since that seems easiest). Let me start off by saying that the ability to use LUA is wonderful and that the new features are a godsend.

Sorta...

Except not having documentation... ;)

So, a few questions:

tabcontrol:
- Is this the only way to do subwindows now?
- Is there a way to switch it to a horizontal layout?
- How do you specify the spacing?
- Is there a way to get rid of the endcaps (other than making them completely blank pngs)

Accessing a subwindow's component:
One of my scripts pops up a window with some choices. Upon choosing something there, it closes the window, and changes the value in the database. I can't, however, figure out how to change the value on the main character sheet.

I have the following code in a script, but it fails because the portrait field is undefined:


local cs = Interface.findWindow("charsheet",getDatabaseNode())

if cs then
cs.main.portrait.setIcon("cs_p"..image)
end


... it starts off by finding the reference to the character sheet and storing it in the variable cs. If that's not nil (meaning it found it), then it tries to set the icon of the genericcontrol named portrait (defined in the subwindow 'main') to the appropriate image file. This fails, spitting out the error that the field 'portrait' is a nil value.

I've also tried just saying "cs.portait.setIcon(blahblah)", but that also fails, for the same reason.

Lastly, I've tried changing the line where it finds the windowinstance to read "local cs = Interface.findWindow("charsheet_main",getDatabaseNode())", but that fails to even find the window (I'm assuming because findWindow can only find a reference to a top level window, and charsheet_main - being a subwindow of charsheet - isn't.

Dynamic image references? File lists?
Is there any way to create a frame or icon during program execution rather than hardcoding it in a file?

Something like: "local img = new icon('path/to/img.png')"?

Also, tied in with this: is there any way to retrieve the contents of a folder, and is there any way to turn the results of that into icons / frame refs?

What I'm trying to accomplish with this: To provide a way to attach a portrait to my character sheet, as evidenced above. Right now, I have to hard code in all of the portraits beforehand. What I'd prefer is a way to just drop them into a folder and have them be able to be selected as options.

I know that we already have the small portraits, but what I'd like is to also have the ability to display a full-body image on the sheet (or something similar).

(I think that's all... phew...)

Edit, already: Is there an easy way to write to the console (for debugging purposes...)... right now, I've been writing it to the chat window... which gets annoying.

Thanks in advance,
-Taryn

Goblin-King
April 27th, 2007, 09:04
tabcontrol:
- Is this the only way to do subwindows now?
- Is there a way to switch it to a horizontal layout?
- How do you specify the spacing?
- Is there a way to get rid of the endcaps (other than making them completely blank pngs)
The tab control is an entirely scripted control. All of it is specified in the scripts, and is something you can override or change (see template_tabcontrol.lua).

You can do subwindows a lot more flexibly. Use <subwindow> elements, place them as you wish and toggle them on/off using setVisible().


Accessing a subwindow's component:
One of my scripts pops up a window with some choices. Upon choosing something there, it closes the window, and changes the value in the database. I can't, however, figure out how to change the value on the main character sheet.
The preferred way of doing things like this is to use the database node for all data changes and make sure the controls are aware of any changes. Most fields should automatically take care of this, but you can use databasenode.onUpdate to monitor the values if necessary.


I have the following code in a script, but it fails because the portrait field is undefined:


local cs = Interface.findWindow("charsheet",getDatabaseNode())

if cs then
cs.main.portrait.setIcon("cs_p"..image)
end


The bit "cs.main" actually refers to the subwindow control, not the actual window in the control. To get there, say "cs.main.subwindow", so "cs.main.subwindow.portrait" should work.


Lastly, I've tried changing the line where it finds the windowinstance to read "local cs = Interface.findWindow("charsheet_main",getDatabaseNode())", but that fails to even find the window (I'm assuming because findWindow can only find a reference to a top level window, and charsheet_main - being a subwindow of charsheet - isn't.
Correct.


Dynamic image references? File lists?
Is there any way to create a frame or icon during program execution rather than hardcoding it in a file?
No. The system does not allow access to the local filesystem for security reasons.


What I'm trying to accomplish with this: To provide a way to attach a portrait to my character sheet, as evidenced above. Right now, I have to hard code in all of the portraits beforehand. What I'd prefer is a way to just drop them into a folder and have them be able to be selected as options.
If you want the players to be able to select these, you're stuck with the portraitselectioncontrol system, look into it. You might also want to experiment with using tokens for this if you are OK with the files being stored on the host.


Edit, already: Is there an easy way to write to the console (for debugging purposes...)... right now, I've been writing it to the chat window... which gets annoying.
Use print(). You can enable the console so it prints stuff other than errors as well by saying "/console".

TarynWinterblade
April 27th, 2007, 09:09
Thanks. :)



The tab control is an entirely scripted control. All of it is specified in the scripts, and is something you can override or change (see template_tabcontrol.lua).

You can do subwindows a lot more flexibly. Use <subwindow> elements, place them as you wish and toggle them on/off using setVisible().

I didn't even think to check if tabcontrol was a template :o



The bit "cs.main" actually refers to the subwindow control, not the actual window in the control. To get there, say "cs.main.subwindow", so "cs.main.subwindow.portrait" should work


I kinda figured there was some way of saying "the window this references" in there. :)



No. The system does not allow access to the local filesystem for security reasons.


I kinda expected that was the answer :ninja:


Anyways, thanks again for the info (and the quick response)