Rick Posted December 5, 2009 Share Posted December 5, 2009 OK I'm confused as to what is happening here. I'm trying to create a GetEntityByName(name) function. In it, it will loop CurrentWorld().entities looking for the key name you pass in. So step one I just want to print all entity names. for model in iterate(CurrentWorld().entities) do Print("Searching name.. "..model:GetKey("Name")) end The thing I don't get is if I put this in the Update() method it prints all the entities, BUT if I put this in a function that gets ran just once from inside Update() (it's like an init thing inside Update() where it'll only run the function inside and if statement) in my log all I see is 1 line of "Searching name... ". It's blank. [EDIT] Here is the code in monster truck lua How it's setup below I see Inside test print in the log but no entities looped through in the log. If I uncomment the GetEntityByName("test") in the Update() method it does loop through all entities. So what's the difference? function Test() Print("Inside test") GetEntityByName("Rick") end function Update(world) local model local entity for model,entity in pairs(entitytable) do entity:UpdateTires() end if(init == false) then if(GetGlobalNumber("game") == 1) then --Print("Running MyScript") init = true --RunScript(MyScript) Test() end end --for m in iterate(CurrentWorld().entities) do -- Print("Searching name.. "..m:GetKey("Name")) --end --GetEntityByName("test") UpdateCR() end Quote Link to comment Share on other sites More sharing options...
Josh Posted December 6, 2009 Share Posted December 6, 2009 I don't think init automatically equals false. It equals nil by default: local p if p==false then Notify("false") end if p==nil then Notify("nil") end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 6, 2009 Author Share Posted December 6, 2009 Oh sorry in spawn I make it false. It gets into the function because I see the Print() in the log that Test() does. So I know it's getting into Test(). Quote Link to comment Share on other sites More sharing options...
Josh Posted December 6, 2009 Share Posted December 6, 2009 The world the Update function is being called for might be a world that has nothing in it. Remember, framewerk has three different worlds going. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 6, 2009 Author Share Posted December 6, 2009 Oh, good call. CurrentWorld(). How do I get the main world's entities? Quote Link to comment Share on other sites More sharing options...
Josh Posted December 6, 2009 Share Posted December 6, 2009 fw.main.world Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 6, 2009 Author Share Posted December 6, 2009 Perfect. Thanks. 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.