AggrorJorn Posted December 9, 2009 Share Posted December 9, 2009 I've made this extra menu for the switch moddel. You can select true or false. --hand icon menu group=grid:AddGroup( "Hand icon" ) group:AddProperty( "Show hand icon", PROPERTY_BOOL ) My question is: How can I retrieve the selected value in the menu, outside the script where I created the menu? Quote Link to comment Share on other sites More sharing options...
Rick Posted December 9, 2009 Share Posted December 9, 2009 You don't access the menu value directly. What you do is in the SetKey() function (you can look at other entities to see how the SetKey() works) for the model you added this property to, you would use http://www.leadwerks.com/wiki/index.php?title=Entities#SetEntityKey to assign this model instance a key/value. In your case you would do something like: model:SetKey("hand_icon", "true") Then in your fps lua file where you pick, you are picking the model and when you get the model you can do: if(model:GetKey("hand_icon")) then -- change icon to the hand icon end So the ideas is you create menu options. When the menu options are set the SetKey() function is called which allows you to assign the value to your entities OR models that you can later get at other places. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 9, 2009 Author Share Posted December 9, 2009 I''l give it a try when I'm back at home (which will be tomorrow). Thx for the reply Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 10, 2009 Author Share Posted December 10, 2009 hmm Although I'm more clear about what the SetKey does, it's not entirely clear where to put them exactly. This is the menu option. group:AddProperty( "showicon",PROPERTY_BOOL,"","Show hand icon") I've added this to the spawn function : function Spawn(model) model:SetKey("showicon","1") This way when a new switch is being dragged on, it has a default value of 1 (true). Next there is the function SetKey(model,key,value). I've place a new model.setkey command but here I get an error. function SetKey(model,key,value) entitymodel:SetKey("showicon","true") The error message "attempt to index global 'entitymodel' (a nill value)". What does this error mean exactly? Quote Link to comment Share on other sites More sharing options...
Rick Posted December 10, 2009 Share Posted December 10, 2009 hmm Although I'm more clear about what the SetKey does, it's not entirely clear where to put them exactly. This is the menu option. group:AddProperty( "showicon",PROPERTY_BOOL,"","Show hand icon") I've added this to the spawn function : function Spawn(model) model:SetKey("showicon","1") This way when a new switch is being dragged on, it has a default value of 1 (true). Next there is the function SetKey(model,key,value). I've place a new model.setkey command but here I get an error. function SetKey(model,key,value) entitymodel:SetKey("showicon","true") The error message "attempt to index global 'entitymodel' (a nill value)". What does this error mean exactly? function SetKey(model,key,value) entitymodel:SetKey("showicon","true") What is entitymodel? The code you posted doesn't show what entitymodel is? If you look at other script examples there is a way to get the lua entity from the model that is being passed into SetKey(). There is something like get_Base() or something that you pass your model into and it returns a lua entity in which you can call SetKey() from. The other route to go is to just use the C++/BMax functions for SetEntityKey() passing in the model that is passed to SetKey(). I'm pretty sure the same result will happen. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 10, 2009 Author Share Posted December 10, 2009 What is entitymodel? That was just a typo in the topic. It is "entity.model'. If I look at the base script and the camera nodes scripts, it seems that this tactic should be working. I'll have another look. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 10, 2009 Share Posted December 10, 2009 I would just try: SetEntityKey(model, "key", "value") Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 10, 2009 Author Share Posted December 10, 2009 I have to be close then: switch.lua group=grid:AddGroup( 'Icon' ) group:AddProperty( 'showicon', PROPERTY_BOOL,'', 'Show hand icon' ) group:Expand(1) end function SetKey(model,key,value) if key=='showicon' then SetEntityKey(model,"switchIcon","true") end end the fpscontroller: -- show hand icon if (GetEntityKey(model,"switchIcon","true")) then handIcon = true end The engine crashes entirely when I approach the switch. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 10, 2009 Share Posted December 10, 2009 I would expect that to work. Are you calling this GetEntityKey in fpscontroller inside the main loop or before it? If it's before it might be an issue as things might not be loaded. Also your true is a string so in your if statement you will need to check for == "true" Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 10, 2009 Author Share Posted December 10, 2009 no it's in the main loop. It's deffinetly the code in the fps that crashes the engine. I''l have another look tomorrow Quote Link to comment Share on other sites More sharing options...
Rick Posted December 11, 2009 Share Posted December 11, 2009 -- show hand icon if (GetEntityKey(model,"switchIcon","true")) then handIcon = true end What surrounding this code? What is model? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 11, 2009 Author Share Posted December 11, 2009 I though that 'model' was some kind of global class. --check hand icon pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,2.0),0,0) if pick~=nil then repeat if pick.entity:GetClass()==ENTITY_MODEL then break end pick.entity=pick.entity.parent until pick.entity==nil -- show hand icon if (GetEntityKey(model,"switchIcon","true"))== true then handIcon = true end else handIcon = false end In a previous topic I wondered if I could change "GetClass()==ENTITY_MODEL " could change into my own kind of class. But this ways seemed the better solution to this. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 11, 2009 Share Posted December 11, 2009 I don't think it is. Try putting pick.entity inside GetEntityKey() instead of model. If that doesn't work try pick.entity.model. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 11, 2009 Author Share Posted December 11, 2009 using if (GetEntityKey(pick.entity,"switchIcon","true")) then results in no errors, but the icon appears on every single model. If I try if (GetEntityKey(pick.entity,"switchIcon","true"))== true then then the hand icon doesn't appear. So it looks like the command is right now, but it doesn't refer to the right key. Also this code seems quite fragile as the editor crashes with the smallest of change. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 11, 2009 Share Posted December 11, 2009 Try if (GetEntityKey(pick.entity,"switchIcon","true")== "true") then true and "true" are not the same thing. "true" is a string and true is a boolean. You are setting the entity key to the string "true" and that if statement you have is trying to compare the key value of either "true" or "false" to true, which isn't the same. It might be better to pick some other value to avoid the confusion for you. Like "yes" or "no" maybe. The good thing is we know that pick.entity is the right value because of your first if statement setting the icon with all models. The reason is because that first if statement is always returning true for some reason. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 12, 2009 Author Share Posted December 12, 2009 I don't think I'm going to solve this any time soon. The logic seems to slip away at some points. I guess I have to wait for some tutorials/ Is there another way to check via pick.entity what kind of model it is? Like say: the pick.entity returns a model name or something? Quote Link to comment Share on other sites More sharing options...
Rick Posted December 12, 2009 Share Posted December 12, 2009 I'll try playing around with this to see what I can do. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 12, 2009 Author Share Posted December 12, 2009 I'll try playing around with this to see what I can do. Thanks for your help. It's really appreciated. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 12, 2009 Share Posted December 12, 2009 I'll need to do this at some point also so it'll be good to know. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.