Jump to content

CurrentWorld().Entities ?


Gabriel
 Share

Recommended Posts

Hello,

 

I wish I had access to all objects in my scene with the script editor (mesh,surface ...)

 

I tried this:

 

function class: CreateObject (model)
    local object = self.super: CreateObject (model)
    e = CurrentWorld().Entities
    f = FindChild (c, "couloir01_2") <- "EXECPTION_ACCESS_VIOLATION"
......

 

Between me and my editor, there is no way to talk about it continually meets EXECPTION_ACCESS_VIOLATION.

 

I'm trying to open dialogue, but nothing;-)

 

someone has an idea to reconcile myself with my editor?

Link to comment
Share on other sites

I suggest adding the relevant entities into a table when they are created, so you can access them later.

 

If you are trying to find a child of that model, you would just call model:FindChild(name).

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

I suggest adding the relevant entities into a table when they are created, so you can access them later.

 

If you are trying to find a child of that model, you would just call model:FindChild(name).

 

ok, but how can I manage that?, in my case, I use the script of models, for example when I place an object on the scene with the editor, I want this object if there is an object in the scene with which it can interact.

 

In this way the only thing I have to do is execute the loadScene ("myscene") and the rest is automatic as in the editor.

Link to comment
Share on other sites

I had never programmed in LUA, I thought I LUA or Basic was the same. I'm stupid to believe it ^ ^

I bought a book on Lua and is more than a vulgar BASIC interpreter, I just found an incredibly powerful language, but not enough restrictive.

I say this because I found a solution to my problem and also with the help of "macklebee"

 

and as I would like to benefit everyone, here is how I solved my problem:

 

 

       Piste = {} -- as global

       local function FindEntityByName(name)
               for model in iterate(CurrentWorld().entities) do
                       if name == model:GetKey("Name") then 
                               return model
                       end
               end
               return nil
      end

       local function GetSurfaceCouloirByName(ModName)
               local ModPiste=FindEntityByName(ModName)
               assert(ModPiste~= nil,"pas trouvé de piste "..ModName.." dans la scène")
               local MeshPiste=ModPiste:FindChild("U3D_STATIC_MESH")
               assert(MeshPiste~= nil,ModName.."trouvé mais pas de mesh portant le nom U3D_STATIC_MESH")
               local NSurfacePiste=MeshPiste:CountSurfaces()
               assert(NSurfacePiste > 0,ModName.."->U3D_STATIC_MESH n'a pas de surface !!!")
               local SurfacePiste=MeshPiste:GetSurface(1)
               return SurfacePiste
       end

       local function StorePathToTable(NonPiste,Surface)
               local CntVertice = Surface:CountVertices()
               assert(CntVertice > 0,"la surface n'a pas de vertice ! <StorePathToTable(Surface)>")
               Piste[NonPiste] = nil
               Piste[NonPiste] = {}
               Piste[NonPiste][0] = Vec3(0)
               for i = 1,CntVertice  do
                       Piste[NonPiste][i] = Surface:GetVertexPosition(i)
               end
       end

       local function ShowPathList(NomPiste)
               local t = Piste[NomPiste]
               local lt = #Piste[NomPiste] - 1
               AppLog(lt)
               for i = 1,lt do
                       AppLog(t[i].x)
               end
       end

function class:CreateObject(model)
       local object=self.super:CreateObject(model)

       AppLog("Begin------------------------------")
               local TheSurface = GetSurfaceCouloirByName("Cou1")
               StorePathToTable("Piste1",TheSurface)
               ShowPathList("Piste1")
       AppLog("End ------------------------------")

 

;-) thank for all

 

Gabriel

Link to comment
Share on other sites

Guest Red Ocktober

hey Gabe... i'm sorta new to this lua mess as well... but, i think you're going through a lot of unnecessary trouble with this...

there should be no need for the extra function (FindEntityByName) just to find a child object of a scene...

 

all you need do to find a child object in a scene is something like in the code below...

 


Graphics(640,480)
RegisterAbstractPath("")
TFilter(1)
AFilter(16)

fw=CreateFramework()


scene=LoadScene("abstract::myNew3.sbx")
fw.main.camera:Movef(0,12,-5)

daynight=scene:FindChild("daynight_2");
daynight:SetKey("rate",4)

while(KeyHit(KEY_ESCAPE)==0 and AppTerminate()==0) do
fw:Update()
fw:Render()
SetBlend(1)
DrawText("Hello There",20,20)
SetBlend(0)
Flip()
end

 

this simple lil lua script loads a scene with Klepto's daynight object, finds the daynight object

and uses the found object variable to set the daynight update rate to 4...

 

ps... i'm using LW 2.50

 

good luck...

 

--Mike

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...