detailsGrid index nil value?

Wardly

Chieftain
Joined
Nov 9, 2014
Messages
39
I'm trying to create a panel to the right of the unit info panel. However when running the following lua script i get an error.


Code:
function OnUnitSelectionShowUnitGroupPanel( p, u, i, j, k, isSelected )
	print("OnUnitSelectionShowUnitGroupPanel: Unit Selected");
	
	gridHeight = 420;
	Controls.DetailsGrid:SetSizeY( gridHeight );
	Controls.ShadowsLeft:SetSizeY( gridHeight );
	Controls.ShadowsRight:SetSizeY( gridHeight );
	Controls.DetailsGrid:ReprocessAnchoring();
	local unitPanelX = ContextPtr:LookUpControl("/InGame/WorldView/UnitPanel/UnitPanelBackground"):GetSizeX();
	Controls.EnemyPanel:SetOffsetX(unitPanelX-62);
	Controls.DetailsGrid:SetOffsetX(unitPanelX-257);

	Controls.DetailsGrid:SetHide(false);
end
Events.UnitSelectionChanged.Add( OnUnitSelectionShowUnitGroupPanel );

the error,
Code:
unitSelect.lua:5: attempt to index a nil value

line five is the following,
Code:
Controls.DetailsGrid:SetSizeY( gridHeight );

Now i'm pretty new to the modding beyond earth but i'm pretty familiar with programming and scripting languages. So to me this looks as though i don't have DetailsGrid in local scope. I've changed the gridHeight var to a standard int and got the same error.

However if i add the following line above everything i would expect it to error but it doesn't.

Code:
grid = Controls.DetailsGrid;

So that makes me think maybe the setSizeY() method is the issue.

Any idea on how i can get this to work?
 
I'd guess there's something wrong with your panel XML, or with the method by which it's added to the mod. If you post your built mod, we can help you troubleshoot it.
 
I didn't even know there was supposed to be a supporting xml file. However after reading your comment i went back and looked over the EnemyUnitPanel.lua and it had a matching EnemyUnitPanel.xml file. So i'll play with that and see what i can come up with when i get back home. I didn't have time to mess with it before i had to leave.

But you answered my question, I'm missing an entire xml file. (containing the DetailsGrid element and other settings) thanks for the help, you saved me a lot of debug headaches and time lost.
 
Ok apparently i'm missing something. So here's the lua script and the xml file. I'm not entirely sure though in the actions section in modbuddy what i set the xml file settings to. I have them set to onModActivated and UpdateDatabase is that correct? It's like the xml file isn't even being loaded, but i don't see any errors in any of the log files other then the error posted with the lua script.


Code:
function OnUnitSelectionShowUnitGroupPanel( p, u, i, j, k, isSelected )
	print("OnUnitSelectionShowUnitGroupPanel: Unit Selected");
	
	local unitPanelX = ContextPtr:LookUpControl("/InGame/WorldView/UnitPanel/UnitPanelBackground"):GetSizeX();
	Controls.UnitGroupInfoGrid:SetOffsetX(unitPanelX-257);

	Controls.UnitGroupInfoGrid:SetHide(false);
end
Events.UnitSelectionChanged.Add( OnUnitSelectionShowUnitGroupPanel );

Code:
<?xml version="1.0" encoding="utf-8"?>
<Context ColorSet="Beige_Black" Style="FontNormal20" FontStyle="Shadow" >
	<AlphaAnim ID="AlphaIn" Size="Full,Full" Cycle="Once" Pause="0" Speed="2" AlphaStart="0" Function="OutQuint" AlphaEnd="1" >
		<Grid ID="UnitGroupInfoGrid" Anchor="L,B" Size="300,126" Offset="430,0" Style="EnemyPanelBackground" >
			<Stack Anchor="L,C" Offset="25,5" StackGrowth="Bottom">

				<!-- Name Header -->
				<Box Anchor="L,T" Offset="0,17" Size="260,24" Color="0,0,255,0" >
					<Label ID="UnitName" Anchor="C,C" Offset="0,-3" Style="BlueShadowText" ColorSet="Gray_Black_Alpha" String="TXT_KEY_UPANEL_UNIT_NAME" ToolTip="TXT_KEY_CURRENTLY_SELECTED_UNIT"/>
					<Label ID="LongUnitName" Anchor="C,C" Offset="0,-3" Style="BlueShadowText" ColorSet="Beige_Black_Alpha" FontStyle="SoftShadow" String="TXT_KEY_UPANEL_UNIT_NAME" ToolTip="TXT_KEY_CURRENTLY_SELECTED_UNIT" Hidden="1" />
					<Label ID="ReallyLongUnitName" Offset="0,-3" Anchor="C,C" Style="BlueShadowText" String="TXT_KEY_UPANEL_UNIT_NAME" ColorSet="Beige_Black_Alpha" FontStyle="Shadow" ToolTip="TXT_KEY_CURRENTLY_SELECTED_UNIT" WrapWidth="235"  Hidden="1" />
				</Box>

				<!-- spacing -->
				<Container Size="1,3" />

				<Box ID="UnitMovementBox" Anchor="L,T" Offset="0,0" Size="310,26" Color="0,0,0,0" >
					<Label ID="UnitStatMovement" Anchor="L,T" Offset="7,0" Style="FontNormal24" String="0/0"  />
				</Box>

				<Box ID="UnitStrengthBox" Anchor="L,T" Offset="0,0" Size="310,26" Color="0,0,0,0"  >
					<Label ID="UnitStatStrength" Anchor="L,T" Offset="0,0" Style="FontNormal24" String="0/0"  />
				</Box>
				
				<Box ID="UnitRangedAttackBox" Anchor="L,T" Offset="0,0" Size="310,27" Color="0,0,0,0"  >
					<Label ID="UnitStatRangedAttack" Anchor="L,T" Offset="6,0" Style="FontNormal24" String="0/0"   />
				</Box>

			</Stack>
		</Grid>
	</AlphaAnim>
</Context>


Code:
LUA/unitSelect.lua:5: attempt to index a nil value

Any help would be greatly appreciated, thanks.
 
Yeah first time modder and finding tid bits here and there that seem to make some of the pieces fall in place.
 
Back
Top Bottom