PDA

View Full Version : dynamic setting of string cycler in a template



rmilmine
April 13th, 2021, 05:07
I have the following for a template using the string cycler.
What is important to note about this code si that the
k and a variables in the for loop get what they are supposed to.
The sValues and sLabels are both set to what they need to be set to.
the problem I am having is that the two lines
self.parameters[1].labelsres[1] = sLabels
self.parameters[1].values[1] = sValues
do not in fact change their values.
The two Debug lines before and after those two lines show the exact same values.
If I try and leave out the dash in the xml part of the code the super.OnInit() will in fact give an error saying that they are a boolean value, which blank xml will end up being recognized as.
I'm not sure what is missing here, I've seen examples of very similar code being done.
I've tried changing this code so that it would use the name of an actual instance of the template and the error still persists.
I am running this code in unity.


<template name="cycler_knowledge_skill_type">
<button_stringcycler>
<parameters>
<defaultlabelres>dash</defaultlabelres>
<labelsres>dash</labelsres>
<values>dash</values>
</parameters>
<script>
function onInit()
local sValues = "";
local sLabels = "";
for k,a in pairs(DataCommon.knowledgeSkillData) do
if sValues ~= "" then
sValues = sValues .. "|" .. k;
else
sValues = k;
end
if sLabels ~= "" then
sLabels = sLabels .. "|" .. "knowledge_skill_type_display_label_" .. k;
else
sLabels = "knowledge_skill_type_display_label_" .. k;
end
end

Debug.console(self.parameters[1].labelsres[1]);
Debug.console(self.parameters[1].values[1]);

self.parameters[1].labelsres[1] = sLabels;
self.parameters[1].values[1] = sValues;

Debug.console(self.parameters[1].labelsres[1]);
Debug.console(self.parameters[1].values[1]);
super.onInit();
end
</script>
</button_stringcycler>
</template>

damned
April 13th, 2021, 07:15
What does



Debug.console(self.parameters[1].labelsres);
Debug.console(self.parameters.labelsres[1]);


output?

Moon Wizard
April 13th, 2021, 16:58
While the stringcycler control wasn't really designed to by dynamic; I can't think of a reason why overriding those values wouldn't work.

As @damned mentioned, what is the output of your Debug statements?
If those are correct, try unpacking CoreRPG and adding Debug into stringcycler onInit to check values there too. (Make sure to remove CoreRPG folder when done to prevent overriding of future changes.)

Regards,
JPG

rmilmine
April 13th, 2021, 17:45
Debug.console(self.parameters[1].labelsres); gives { #1 = s'dash' }
Debug.console(self.parameters.labelsres[1]); gives an error attempt to index field 'labelsres' (a nil value)
I did unpack CoreRPG in order to figure out that this was the problem. I put debug statements all over the place to figure out where the problem was happening.
At first the error I was getting was that the label and value fields were boolean and that split was trying to get a length on it. This was happening because I had left the xml empty.
When I realized that this was the case I went back to the assignment statement and found that it was in fact not actually assigning my values to these fields. I will try this again in classic to see if it still works there, I'm pretty sure that this did work before.

damned
April 13th, 2021, 22:02
which debug gives you the right value?

Debug.console(self.parameters[1].labelsres[1]);
Debug.console(self.parameters[1].labelsres);
Debug.console(self.parameters.labelsres[1]);

rmilmine
April 13th, 2021, 22:31
before assignment
self.parameters[1].labelres[1] gives me s'dash' (expected)
self.parameters[1].labelres gives me { [1] = s'dash' } again expected
self.parameters.labelres[1] gives an error as above.

after assignment it's the same as above.

in essence, none of the above give the right answer after the assignment, but they are correct before.

damned
April 13th, 2021, 22:39
And what about:

Debug.console(self.parameters);

Moon Wizard
April 13th, 2021, 22:53
self.parameters.labelres[1] is not valid. When FG converts XML to local variables, it always places in table because XML can have more than one tag with the same name.

Regards,
JPG

rmilmine
April 14th, 2021, 01:43
self.parameters gives exactly what is expected { #1 = {s'values'={ #1 = s'dash'}, s'labelsres'={ #1 = s'dash'}, s'defaultlabelres'={ #1 = s'dash'}}}

It gives this both before and after assignment.
It's all rather strange.

rmilmine
April 14th, 2021, 02:30
So I tried running this code in classic and it works fine, it gives the expected outcome with the fields changing, it's only in unity that it doesn't change.

rmilmine
April 15th, 2021, 00:20
Anyone have a suggestion on how to get around this? I have a couple of ideas, but really hoping there is something simple.

rmilmine
April 19th, 2021, 20:01
Anyone know where I can report this as a bug in Unity?

Moon Wizard
April 19th, 2021, 21:04
What exactly do you think is a bug?

Regards,
JPG

rmilmine
April 20th, 2021, 19:19
The code in the first post works in Classic but does not work in Unity.
Specifically the lines:

self.parameters[1].labelsres[1] = sLabels;
self.parameters[1].values[1] = sValues;

work fine in Classic but do not work in Unity.

Moon Wizard
April 21st, 2021, 01:28
I was able to recreate the scenario; but I don't know why it's behaving differently off the top of my head nor whether it's something I can change in FGU without breaking other assumptions.

For now, you'll have to write your own cycler template.

Regards,
JPG

rmilmine
April 21st, 2021, 04:37
Well as long as you know about it, hopefully it can get fixed I have a way around it I think.