Label to show current expansion
-
I am trying to create a label to show the currently selected expansion but I can only get it to show the object name not the actual name of the expansion.
I have used this code to do the same for the preset name and it works fine
Content.getComponent("PresetName").set("text", Engine.getCurrentUserPresetName());
but when I use this code for the expansion name using this (ExpName is just the label)
Content.getComponent("ExpName").set("text", expHandler.getCurrentExpansion());
I get the object name instead as well as a warning in the console saying
! You must specify the unique component name, not the object itself
How can I get the expansion text name and then apply that to the label please?
-
@rzrsharpeprod get current expansion returns an expansion object not a text string. You need to get the properties of this object which contains the name.
-
The array that contains the expansion names is called expansionNames in my project
What do I need to put after this part to call the expansionNames current name please?Content.getComponent("ExpName").set("text",
I looked through the API and am struggling to see what I need to use.
I have triedContent.getComponent("ExpName").set("text", expansionsNames.push(p.Name));
and
Content.getComponent("ExpName").set("text", expansionsNames.getProperties().Name);
but am getting errors as it clearly isn't right. I can usually find examples or something to help me figure out the syntax but I am struggling when it comes to expansions as there doesn't seem to be too much out there other than your 2 tutorials and a little in the API.
-
const currentExpansion = expHandler.getCurrentExpansion(); // Returns an Expansion object - so you can use any functions that are listed under Expansion in the API. const expansionProperties = currentExpansion.getProperties(); const expansionName = expansionProperties.Name;
-
@d-healey said in Label to show current expansion:
By changing these to const vars and having them above the code to populate the label, I can get it to work but it only works for the initial expansion. It doesn't change when I switch expansions unless I recompile.
I have done this as you suggested
const var currentExpansion = expHandler.getCurrentExpansion(); const var expansionProperties = currentExpansion.getProperties(); const var expansionName = expansionProperties.Name;
and this is in the else clause of my label populate script
Content.getComponent("ExpName").set("text", expansionProperties.Name);
but it doesn't change without recompiling. What am I missing?
-
@rzrsharpeprod You don't have to use
const
, I was just using it for the example. Use the appropriate variable type for the code you're working on. You will want to update the name when the expansion is changed presumably, so put the code in that part of your script. -
@d-healey Got it working, thankyou.
Obviously it has to go in the part of the code where the change happens...for whatever reason that basic concept had escaped me. Thanks again