Home › Forums › General › Programming › Since I upgraded.
- This topic has 7 replies, 3 voices, and was last updated 11 years, 2 months ago by Bomma72.
-
AuthorPosts
-
January 25, 2013 at 5:32 am #5806
I am having trouble with my string variables. After I define them or if I populate them with the value of a label when I try to run the len command or the string.sub command I always get an error.
“string expected, got userdata”
This didn’t happen before. Not sure what is different now.
January 25, 2013 at 11:59 pm #5825So did some more checking and the weirdest thing about this is that if I do a console command it I get the string value.
January 26, 2013 at 7:08 am #5835OK after the second night of trying to figure this out I am starting to think this may be a bug with the newly compiled Mac version of Ctrlr. I just don’t know. Seems to only happen with strings, though maybe I am doing something wrong.
Here is an example of the code I am trying to use.
label = panel:getModulatorByName(“lblPhTtl”):getComponent()
local PatchName = label:getPropertyString(“uiLabelText”)for i=1,10 do
char = string.sub(PatchName,i,i) –Tried this first
** returns bad argument #1 to ‘sub’ (string expected, got userdata).
char = PatchName:getByte(i) — Then tried this** returns attempt to call method ‘getByte’ (a nil value)
end
I should mention that there is data in the label field and if I do a console(PatchName) command I get the correct results. Also this worked fine with the current build that is defaulted to on the site. Should I just go back to that one?
January 26, 2013 at 8:51 am #5838Try changing local PatchName = label:getPropertyString(“uiLabelText”) with local PatchName = label:getProperty(“uiLabelText”)
January 26, 2013 at 6:10 pm #5847Hi, Thanks for the reply. So I tried to put your command into practice however, same issue. For whatever reason all of the strings taken from the label are seen as userdata and I can’t even convert them to string as it say they are nil when I try. I also changed the label thinking maybe this was a legacy issue. No such luck.
At this point I am going to go back to the older version of Ctrlr though I hate to do it.
January 26, 2013 at 6:37 pm #5848It’s all String() classes, always look at your object for what they are, i included a handy what() mehtod for example
>>> l = panel:getComponent("myLabel"):getProperty("uiLabelText") debug (what (l)) console (l) Object type [string] ----------------------------------------------------------------- Members: Attributes: ----------------------------------------------------------------- Object type [string] ----------------------------------------------------------------- Members: Attributes: ----------------------------------------------------------------- Label text
Or:
>>> l = panel:getLabel("myLabel"):getText() debug (what (l)) console (l) Object type [String] ----------------------------------------------------------------- Members: equalsIgnoreCase: function __init: function toLowerCase: function lastIndexOfIgnoreCase: function removeCharacters: function paddedRight: function contains: function swapWith: function getHexValue32: function fromLastOccurrenceOf: function indexOfIgnoreCase: function startsWith: function length: function quoted: function trimCharactersAtStart: function endsWith: function matchesWildcard: function unquoted: function getFloatValue: function containsOnly: function containsWholeWordIgnoreCase: function hashCode: function repeatedString: function isQuotedString: function compareLexicographically: function compare: function getIntValue: function append: function upToFirstOccurrenceOf: function startsWithIgnoreCase: function getLastCharacters: function lastIndexOf: function isEmpty: function containsIgnoreCase: function retainCharacters: function indexOf: function replaceSection: function initialSectionContainingOnly: function isNotEmpty: function containsAnyOf: function trimCharactersAtEnd: function lastIndexOfAnyOf: function initialSectionNotContaining: function replace: function substring: function indexOfAnyOf: function trim: function fromFirstOccurrenceOf: function dropLastCharacters: function toUpperCase: function trimEnd: function containsWholeWord: function indexOfWholeWordIgnoreCase: function compareIgnoreCase: function containsNonWhitespaceChars: function __add: function upToLastOccurrenceOf: function indexOfWholeWord: function getTrailingIntValue: function paddedLeft: function getDoubleValue: function replaceCharacters: function toUTF8: function Attributes: ----------------------------------------------------------------- Object type [String] ----------------------------------------------------------------- Members: equalsIgnoreCase: function __init: function toLowerCase: function lastIndexOfIgnoreCase: function removeCharacters: function paddedRight: function contains: function swapWith: function getHexValue32: function fromLastOccurrenceOf: function indexOfIgnoreCase: function startsWith: function length: function quoted: function trimCharactersAtStart: function endsWith: function matchesWildcard: function unquoted: function getFloatValue: function containsOnly: function containsWholeWordIgnoreCase: function hashCode: function repeatedString: function isQuotedString: function compareLexicographically: function compare: function getIntValue: function append: function upToFirstOccurrenceOf: function startsWithIgnoreCase: function getLastCharacters: function lastIndexOf: function isEmpty: function containsIgnoreCase: function retainCharacters: function indexOf: function replaceSection: function initialSectionContainingOnly: function isNotEmpty: function containsAnyOf: function trimCharactersAtEnd: function lastIndexOfAnyOf: function initialSectionNotContaining: function replace: function substring: function indexOfAnyOf: function trim: function fromFirstOccurrenceOf: function dropLastCharacters: function toUpperCase: function trimEnd: function containsWholeWord: function indexOfWholeWordIgnoreCase: function compareIgnoreCase: function containsNonWhitespaceChars: function __add: function upToLastOccurrenceOf: function indexOfWholeWord: function getTrailingIntValue: function paddedLeft: function getDoubleValue: function replaceCharacters: function toUTF8: function Attributes: ----------------------------------------------------------------- Label text
Always know what data you are dealing with
January 26, 2013 at 8:07 pm #5850This is what I do to get characters from a uiLabel string:
label = panel:getModulatorByName("Patch Name"):getComponent()
PatchName= label:getProperty ("uiLabelText")character1 = string.byte((PatchName), 1)
..
character10 = string.byte((PatchName), 10)Hope this helps
January 29, 2013 at 4:57 am #5893Thanks for this, I got it!!
I was using
PatchName = label:getPropertyString(“uiLabelText”)
PatchName = label:getProperty
String(“uiLabelText”)Removing the string part works.
It’s strange as the other worked worked in the old version, and like I said it also would display the string when I called it in the console. Anyway know I know.
Thanks again.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.