PDA

View Full Version : Accessing XML Parameters from Scripts



Varsuuk
June 13th, 2023, 22:04
This section always confused me - I sometimes get "dense" with things and have to revaluate it later. I did so, several times for a minute or 3 over a long time, everytime I came across this. I so very rarely used the indexing and when I did, I simply bruteforced it if I got it wrong until it was right. But I wanted to always "grok" it.
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644496/Ruleset+-+Scripting#Accessing-XML-Parameters-from-Scripts

I recenty USED the [1]/[2] on my own in a script correctly and remembered to check again. This time, I still didn't get why "empy" & "normal" were treated so differently than "first" & "last". So, fed up with my denseness - I did what I always do, setup a test app. In this case the code I was working on, I added a simple control to and looked at the output:



<genericcontrol>
<states>
<empty>
<icon>emptyicon</icon>
</empty>
<normal>
<icon>normalicon</icon>
</normal>
</states>
<flags>
<first />
<second />
</flags>
<label>Control label</label>
<script>
function onInit()
Debug.console(states)
Debug.console(flags)
Debug.console(label)
end
</script>
</genericcontrol>


And the result:
57701

So, it seems my confusion was because for all these years that wiki page was in error? There IS no [2] to be seen, I couldn't figure out what there would be...

Moon Wizard
June 13th, 2023, 23:56
I've fixed the example on that page to match the example tags.

The additional indexes will only appear if multiple tags with the same name are defined.

For example:


<buttoncontrol>
<state><icon>buttonicon</icon</state>
<state><icon>buttonicon_down</frame></state>
<script>
function onInit()
Debug.console(state)
end
</script>
</buttoncontrol>

would return:


state = {
[1] = {
icon = {
[1] = "buttonicon",
},
},
[2] = {
icon = {
[1] = "buttonicon_down",
},
},
}


Regards,
JPG

Varsuuk
June 14th, 2023, 04:49
Cool that is exactly how I thought I understood it, the point of the array, but the example always vexxed me. Glad I finally gave up reading it and tried it.
Basically, I hadn't USED repeating groups until I worked on a template recently and that's when I remembered to go back and look at it again.