Senior Member
Join Date: Nov 2013
Location: Andover, Ma
Posts: 632
|
I'm trying to deepen my knowledge of hero labs code and break into some of the more crazy aspects of the code. :P So this is completely new territory for me hehe.
I am trying to create a custom ability with a chooser that references an element within a gizmo. I have found a way to grab the name of the specific entity that I want to grab, but I cannot find a way to use that in the custom expression. What I want to do is have a dropdown that selects each settlement in the kingdom so I can make adjustments on buildings do in each settlement and a variety of other operations. I can grab the name of each settlement and display it in the debug using a script but I cant figure out a way to use this to create a custom expression to create a custom ability which uses the Name of the Settlement for the choice rather than the name of the parent terrain type (which is the parent element the gizmo is attached to). Or the name of the settlement tag (either Settlement or Settlement Expansion) Render/9000 Code:
~ Seach the Kingdom Hexes and find those with a settlement foreach pick in hero from KingHex where "HexFeature.Settle" debug "Settlement Names: " & eachpick.field[hxName].text debug "Settlement IDSTRING: " & eachpick.idstring debug "thingid." & eachpick.idstring & "|" nexteach |
#1 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,213
|
Here's my article about traveling between contexts (since what you want to do is to travel from the hex pick you've found to the gizmo of that pick, and then to the children within that gizmo: http://forums.wolflair.com/showthread.php?t=21663
Post #3 is about the pick context, and "eachpick" lets you target a specific pick, so that's the context you're in. |
#2 |
Senior Member
Join Date: Nov 2013
Location: Andover, Ma
Posts: 632
|
Well, I had already examined that, and took from it what I could. I am honestly begining to think that it isnt an issue with the code that I have as it appears from the debug output that I should get some positive result.
Instead when I look at the usrCandid1 gives um.. EVERYTHING as an option instead of being limited to the custom expression that I HL says that it should be using. Using this code: Code:
debug "~~~~~~ Settlement & Building Selection ~~~~~~~" debug "{b}Location:{/b} cLGCoEdict | {b}Timing:{/b} Render/999999/1" ~ Seach the Kingdom Hexes and find those with a settlement foreach pick in hero from KingHex where "HexFeature.Settle" debug "===============================================" debug "{b}Settlement Name:{/b} " & eachpick.field[hxName].text foreach pick in eachpick.gizmo where "TerrImpCat.Building" debug "{b}Gizmo ID:{/b} " & eachpick.idstring nexteach field[abText].text &= "thingid." & eachpick.idstring & "|" nexteach debug "===============================================" debug "=====================END======================" debug "abText : " & field[abText].text field[usrCandid1].text &= field[abText].text |
#3 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,213
|
Problem #1 - as coded, your candidate Id will always end in "|", with no final tag Id - that will fail to be recognized as a valid candidate expression, meaning HL defaults to "absolutely everything" for the drop-down.
Problem #2 - A drop-down menu can only select within the container it is in (or from inside a gizmo, it can be set to select things in the hero container). It cannot select from among the picks inside another pick's gizmo. Try adding a "building" that can be added to the settlement it's being applied to that can then select from among the buildings in its same settlement (same gizmo). then, if this is more of an ability than a building you'd build in some settlement, you can look for ways to hide it in most cases, but still leave it visible within that settlement so the user can select the building to apply it to. Oh, and coding style note - don't use idstring unless there's no other option. eachpick.tagids[thingid.?,"|"] would give you the same result. |
#4 |
Senior Member
Join Date: Nov 2013
Location: Andover, Ma
Posts: 632
|
Quote:
2) Yeah, adding new buildings isnt the issue, I need to access EXISTING buildings because I need to alter their fields and tags. So I assumed that the only way to do that would be to find the settlement they are in and then just going down until I get to the building... That isnt possible? How would I alter tags and fields of existing buildings? |
|
#5 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,213
|
tagid wouldn't solve that, but string manipulation should always be avoided if you can - it's faster for HL to process tags than strings.
Here's what can: Code:
field[abText].text = splice(field[abText].text,eachpick.tagids[thingid.?],"|") splice() appends the first two arguments together, and if both of them have something in them, it puts the third argument in-between them, so that way, there's only ever "|" between tags - since field[abText].text is empty for the very first item it finds, it doesn't add the "|", but it does for all the other tags. You can alter their tags and fields, but you can't use a drop-down to select which one to alter - drop-downs have only two containers they can choose from - their own, or the hero, and here, you have an ability that's external to the settlement that wants to offer a drop-down of choices within the gizmo of something else. So, the work-around I'm suggesting is that instead of running this script from an external thing, have the user add a fake building to the settlement that can then apply changes to the other things in that same settlement. |
#6 |
Senior Member
Join Date: Nov 2013
Location: Andover, Ma
Posts: 632
|
Quote:
Hmm, is there an example of this in concept so I'd be able to see it in practice? I'm not exactly sure how I'd force bootstrap a building to every settlement on demand. And also make it hidden so that the player cannot see it. I'd also at least like to be able to keep have the chooser for the player's benefit to keep track of what they are altering or working with. Even if it doesnt functionally do anything. Thank you for helping with this, I am enjoying the challenge of learning new aspects of code. |
|
#7 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,213
|
If this is a thing that's selecting a specific building in every settlement, but always applies to all settlements, that's entirely different than the ability I thought you were writing, based on the questions you've been asking. Please post the description text of what you're creating, so I can evaluate what the best approach is.
|
#8 |
Senior Member
Join Date: Nov 2013
Location: Andover, Ma
Posts: 632
|
Quote:
The rulers of a city can commission an item to be constructed provided that their is an appropriate building that can make magical items of that type. You need to know what settlement to use and which building in that settlement to use. You also need to know the gp cost of the item for calculating unrest. If their are more than one building that can produce magical items (in a single city) and you force more than one the unrest increases. You can also use the commission edict to reduce the BP cost of buildings in the same settlement or terrain improvements in adjacent hexes by 2 BP for a medium for EACH major item slot being expended and by 1 for each medium item slot expended. This alternate use, i am fairly certain I know how to do once I can manipulate the buildings. So, yes Specific settlement and specific singular buildings within that settlement. This would only affect ONE building of that type within a settlement not all buildings in the settlement nor all buildings of that type in the kingdom. This basic concept will be needed repeatedly, as will the ability to alter ALL buildings (both in a settlement and kingdom), which I expect to give me a great deal of trouble if I cannot figure a way to add additional tags and fields to some elements. But I will cross that bridge when I come to them. |
|
#9 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,213
|
This is not something we would implement with something that chooses settlements and buildings if we were doing this book (maybe just a text field to let the user write those in) - this doesn't create long-term record keeping entries on the kingdom other than the initial cost of the edict, and recording the finished magic item at the end - just let the user fill in the amount of unrest for the exact details of how they're implementing the edict.
Manipulating costs of things that the user is purchasing before the user purchases them (so that the cost is changed for the user) is not something that can be done from the editor - you need access to the core files and the purchase scripts. So that will also have to be a text-only ability that is up to the user to apply at the game table. |
#10 |
|
|