-
April 13th, 2021, 05:07 #1
- Join Date
- Nov 2019
- Posts
- 282
dynamic setting of string cycler in a template
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.
Code:<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>
Last edited by Trenloe; April 13th, 2021 at 06:31. Reason: Moved to the workshop forum
-
April 13th, 2021, 07:15 #2
What does
Code:Debug.console(self.parameters[1].labelsres); Debug.console(self.parameters.labelsres[1]);
-
April 13th, 2021, 16:58 #3
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,566
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
-
April 13th, 2021, 17:45 #4
- Join Date
- Nov 2019
- Posts
- 282
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.
-
April 13th, 2021, 22:02 #5
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]);
-
April 13th, 2021, 22:31 #6
- Join Date
- Nov 2019
- Posts
- 282
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.
-
April 13th, 2021, 22:39 #7
And what about:
Debug.console(self.parameters);
-
April 13th, 2021, 22:53 #8
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,566
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
-
April 14th, 2021, 01:43 #9
- Join Date
- Nov 2019
- Posts
- 282
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.
-
April 14th, 2021, 02:30 #10
- Join Date
- Nov 2019
- Posts
- 282
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.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks