PDA

View Full Version : [Star Wars Saga Edition] Feats Module



aarsene
September 24th, 2011, 01:52
I have just started using FG and am quite impressed by it. I am using the Star Wars Saga Edition ruleset that is available on these forums based on the 4e ruleset.

I have started to build the content modules for my players (Feats, Skills, Talents, etc...) and have figured out most of the stuff I need. I have a question to complete the Feats module which I can't seem to figure out. Is there a way to detect is a formatedtext field exists or not. I have tried to see if the value is empty ("") but it always has a value, even if the XML entry does not exist. It seems that by default <p></p> are assigned to the field so it is never empty. I have tried to explicity verify for that string but I get a parser error.

This works fine for a type string but unfortunately not what I need.

Here is the script I have. I think i'm close but just can't get it...


<script>
function onInit()
local prerequisiteStr = string.lower(NodeManager.get(getDatabaseNode(), "prerequisite", ""))
if not prerequisiteStr == "" then
label_prerequisite.setVisible(false)
prerequisite.setVisible(false)
end
end
</script>

Thanks for any help

Moon Wizard
September 24th, 2011, 18:20
You might try

prerequisites ~= ""

or

not (prerequisites == "")

Regards,
JPG

aarsene
September 24th, 2011, 18:37
Thanks for the quick reply.

I actually tried that before posting. It seems that the formatedtextfield is never empty (even if the entry does not exist in the XML). It seems to always have an opening and closing "p" tag.

I tried to see it if was equal to the tags but it causes a script error.

I tried the below code and the 2 fields are always visible even if the content is not supposed to exist.


<script>
function onInit()
if prerequisite ~= "" then
label_prerequisite.setVisible(true);
prerequisite.setVisible(true);
else
label_prerequisite.setVisible(false);
prerequisite.setVisible(false);
end
end
</script>

Here is the sample XML I am using:


<?xml version="1.0" encoding="iso-8859-1"?>
<root version="2.0">
<library static="true">
<feats>
<name type="string">SWSE Feats</name>
<categoryname type="string">Feats</categoryname>
<entries>
<acrobaticstrike>
<librarylink type="windowreference"><class>featdesc</class><recordname>..</recordname></librarylink>
<name type="string">name here</name>
<source type="string">Feat</source>
<description type="formattedtext">
<p>content here</p>
</description>
<prerequisite type="formattedtext">
<p>content here</p>
</prerequisite>
<benefit type="formattedtext">
<p>Content here</p>
</benefit>
<rulebook type="string">Core Rulebook</rulebook>
<rulebookpage type="string">82</rulebookpage>
</acrobaticstrike>
</entries>
</feats>
</library>
</root>

EDIT: I also tried to add the EMPTY tag to the formattedtext display and the empty content never appears.

Zeus
September 24th, 2011, 19:02
Try this.


<script>
function onInit()
local ptext = prerequisite.getDatabaseNode().getValue();
if ptext and (not ptext == "") then
label_prerequisite.setVisible(true);
prerequisite.setVisible(true);
else
label_prerequisite.setVisible(false);
prerequisite.setVisible(false);
end
end
</script>

aarsene
September 24th, 2011, 19:25
No dice DrZeuss.

I changed the script a little to show what is happening. I am displaying the value of the formattedtextfield in the label field. See the attached images to see what is being displayed.


<script>
function onInit()
local ptext = prerequisite.getDatabaseNode().getValue();
if ptext and (not ptext == "") then
label_prerequisite.setVisible(true);
prerequisite.setVisible(true);
else
prerequisite.setVisible(false);
label_prerequisite.setValue(ptext);
end
end
</script>

https://ioc.net.modernmedia.ca/with-preequisite.jpg
https://ioc.net.modernmedia.ca/without-preequisite.jpg

aarsene
September 24th, 2011, 19:28
What I am trying to do is remove the fields from the display if they are empty along with the corresponding label. Once I have it figured out for the prerequisite field I can apply it to the Special and Normal fields/labels.

If you have another way of doing this I am also open to that.

Thanks for your help

Zeus
September 24th, 2011, 19:53
OK, does this work?



<script>
function onInit()
local ptext = prerequisite.getDatabaseNode().getValue();
if ptext and string.len(ptext) > 7 then
label_prerequisite.setVisible(true);
prerequisite.setVisible(true);
else
prerequisite.setVisible(false);
label_prerequisite.setValue(ptext);
end
end
</script>

aarsene
September 24th, 2011, 20:23
GOT IT. Thanks DrZeuss.

I had to modify the script very slightly but got it to work. Seems the magic number is 8 rather than 7. I also reversed the logic to keep the script shorter. Curious however when I tried to use the less than symbol it crashed. I ended up using a NOT and got the same result.


<script>
function onInit()
local ptext = prerequisite.getDatabaseNode().getValue();
if not (string.len(ptext) > 8) then
label_prerequisite.setVisible(false);
prerequisite.setVisible(false);
end
end
</script>

Zeus
September 24th, 2011, 20:33
Glad you got it working.