DICE PACKS BUNDLE
Page 1 of 2 12 Last
  1. #1

    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

  2. #2

  3. #3
    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

  4. #4
    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.

  5. #5
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,655
    Blog Entries
    1
    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]);

  6. #6
    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.

  7. #7

  8. #8
    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

  9. #9
    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.

  10. #10
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in