StonedWizard Posted July 27, 2015 Share Posted July 27, 2015 I need help with create context menu in game.function TerraformingNamespace.createContextMenu(player, context, worldobjects) local TFOption = context:addOption("Terraforming", worldobjects, nil, nil, player); local TFSubmenu = ISContextMenu:getNew(context); context:addSubMenu(TFOption, TFSubmenu); local EnableOpt = TFSubmenu:addOption("Enable", worldobjects, TerraformingNamespace.EnableTF); local BrushType_Earth = TFSubmenu:addOption("Dirt", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_64"), nil); local BrushType_Grass = TFSubmenu:addOption("Grass", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_60"), nil); local BrushType_Water = TFSubmenu:addOption("Water", worldobjects, TerraformingNamespace.SetBrush("blends_natural_02_0"), nil);endEvents.OnFillWorldObjectContextMenu.Add(TerraformingNamespace.createContextMenu);but subMenu dont create in context menu! Whats wrong? Link to comment Share on other sites More sharing options...
ethanwdp Posted July 27, 2015 Share Posted July 27, 2015 The error I'm getting is that you're trying to attempt an index of a non-table on line 1. The problem is you forgot to define TerraformingNamespace. Try this: TerraformingNamespace = {} -- defines the table function TerraformingNamespace.createContextMenu(player, context, worldobjects) local TFOption = context:addOption("Terraforming", worldobjects, nil, nil, player); local TFSubmenu = ISContextMenu:getNew(context); context:addSubMenu(TFOption, TFSubmenu); local EnableOpt = TFSubmenu:addOption("Enable", worldobjects, TerraformingNamespace.EnableTF); local BrushType_Earth = TFSubmenu:addOption("Dirt", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_64"), nil); local BrushType_Grass = TFSubmenu:addOption("Grass", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_60"), nil); local BrushType_Water = TFSubmenu:addOption("Water", worldobjects, TerraformingNamespace.SetBrush("blends_natural_02_0"), nil);endEvents.OnFillWorldObjectContextMenu.Add(TerraformingNamespace.createContextMenu); The console is your friend! Link to comment Share on other sites More sharing options...
StonedWizard Posted July 27, 2015 Author Share Posted July 27, 2015 The error I'm getting is that you're trying to attempt an index of a non-table on line 1. The problem is you forgot to define TerraformingNamespace. Try this: TerraformingNamespace = {} -- defines the table function TerraformingNamespace.createContextMenu(player, context, worldobjects) local TFOption = context:addOption("Terraforming", worldobjects, nil, nil, player); local TFSubmenu = ISContextMenu:getNew(context); context:addSubMenu(TFOption, TFSubmenu); local EnableOpt = TFSubmenu:addOption("Enable", worldobjects, TerraformingNamespace.EnableTF); local BrushType_Earth = TFSubmenu:addOption("Dirt", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_64"), nil); local BrushType_Grass = TFSubmenu:addOption("Grass", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_60"), nil); local BrushType_Water = TFSubmenu:addOption("Water", worldobjects, TerraformingNamespace.SetBrush("blends_natural_02_0"), nil);endEvents.OnFillWorldObjectContextMenu.Add(TerraformingNamespace.createContextMenu); The console is your friend!Table is init, but I not posted this part of code... Oh, thx for so fast answer. Problem was in next code, I write '==' instead '=' Link to comment Share on other sites More sharing options...
ethanwdp Posted July 27, 2015 Share Posted July 27, 2015 The error I'm getting is that you're trying to attempt an index of a non-table on line 1. The problem is you forgot to define TerraformingNamespace. Try this: TerraformingNamespace = {} -- defines the table function TerraformingNamespace.createContextMenu(player, context, worldobjects) local TFOption = context:addOption("Terraforming", worldobjects, nil, nil, player); local TFSubmenu = ISContextMenu:getNew(context); context:addSubMenu(TFOption, TFSubmenu); local EnableOpt = TFSubmenu:addOption("Enable", worldobjects, TerraformingNamespace.EnableTF); local BrushType_Earth = TFSubmenu:addOption("Dirt", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_64"), nil); local BrushType_Grass = TFSubmenu:addOption("Grass", worldobjects, TerraformingNamespace.SetBrush("blends_natural_01_60"), nil); local BrushType_Water = TFSubmenu:addOption("Water", worldobjects, TerraformingNamespace.SetBrush("blends_natural_02_0"), nil);endEvents.OnFillWorldObjectContextMenu.Add(TerraformingNamespace.createContextMenu); The console is your friend!Table is init, but I not posted this part of code... Ah, okay. I misinterpreted the question, my bad. If you want the Enable sub menu to appear, you have to register it as one. Try this: TerraformingNamespace = {} -- defines the tablefunction TerraformingNamespace.createContextMenu(player, context, worldobjects) local TFOption = context:addOption("Terraforming", worldobjects, nil, nil, player); local TFSubmenu = ISContextMenu:getNew(context); context:addSubMenu(TFOption, TFSubmenu); local EnableOpt = TFSubmenu:addOption("Enable", worldobjects, nil); -- you only need to call a function when it's a button, which is why I replaced it with nil local subMenuEnable = TFSubmenu:getNew(TFSubmenu); context:addSubMenu(EnableOpt, subMenuEnable); -- adds the sub menu named subMenuEnable to the EnableOpt option local BrushType_Earth = subMenuEnable:addOption("Dirt", worldobjects, function() TerraformingNamespace.SetBrush("blends_natural_01_64") end) -- add an option to subMenuEnable. use an anonymous function wrapper for this, because functions you're passing to addOption directly will instantly execute when you so much as mouse over it local BrushType_Grass = subMenuEnable:addOption("Grass", worldobjects, function() TerraformingNamespace.SetBrush("blends_natural_01_60") end); local BrushType_Water = subMenuEnable:addOption("Water", worldobjects, function() TerraformingNamespace.SetBrush("blends_natural_02_0") end); endEvents.OnFillWorldObjectContextMenu.Add(TerraformingNamespace.createContextMenu); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now