Jump to content
Raul

How to access objects from my SBX map

Recommended Posts

I had a look over the Blitzmax templates from the LEBuilder and remake the tutorials. I was able now to load and render my map made with the Editor.

 

Just wondering how could I access my objects from the map now.

 

 

Also I am interested in adding some models. I tried this simple code right after my map was loaded and before entering in main loop:

 

body:TBody = CreateBodyBox()
SetBodyMass body, 1
For n = 1 To 100
body = TBody(CopyEntity(body))
PositionEntity body, Vec3(Rnd(-5, 5), n, Rnd(-5, 5))
Next

 

but no cubes were visible..

Share this post


Link to post

Hi Raul, good to see you back :)

 

The variable you used when using the LoadScene command is effectively a pointer to a collection with all of the sbx file's objects as children. You can iterate through these to access them and if need be build your own specialised collections.

 

Bodies in LE are a physics type representation for use with meshes and not actually meshes themselves, so you will have no visible component for a body!

 

Worth taking a look at the Leadwerks Developer Wiki on these items.

Share this post


Link to post

For Local e:TEntity = EachIn CurrentWorld().Entities

Select GetEntityKey(e, "Name")

 

Heres one way of referencing objects in editor.

Share this post


Link to post

@Pixel Perfect: right. my bad. forgot to actually add a Mesh... now is working. thanks

The only problem is that all the boxes are going through the terrain. How should I add the collision between the rest of the world and my boxes?

 

@Cassius:

ok. right before starting the main loop I entered the following:

 

For Local e:TEntity = EachIn CurrentWorld().Entities
    Select GetEntityKey(e, "Name")
         Case "a_1"
         MoveEntity(e, [e.position.x, e.position.y + 5, e.position.z])
    End Select
Next

 

And my tree was up there. That's good.

 

My next question would be: is this a good practice in real time? I mean, let's assume I have a character and I move it through the world. I want to check if my character is near a door and when I press "E" to open that door... or do anything with it. is there ok to make a "search" through all the entities and when I found the door to retrieve it? Is there another way to directly access that object?

Share this post


Link to post

To get your meshes reacting to anything other than straight collision you need to create bodies for them, either in code or using the phygen tool. Then set up collision between them by assigning an entity type to each and using the Collisions command.

 

In terms of efficiency I'm not sure how things are handled in BMax but in C++ you would probably want to use something like a Map container which allows you to tag the object pointer with a text label and the pair are indexed by the label; making for fast and efficient retrieval. If you only have a few objects then indexed retrieval is not important, but if you have hundreds or thousands then it starts to make a difference.

 

I would strongly recommend reading through Aggror's Leadwerks Guide here it will save you much time in the long run

Share this post


Link to post

@Pixel Perfect:

I already have the body for that boxes. I just added EntityType = 1 for every box. Now I have coll detection with the ground and with my rocks.

 

For point 2, I might create (after my scene is loaded) an array of entitites... I could store what I need and make the checks during the mainloop.

 

Damn this is difficult. I do not have any REAL experience with 3D games. Except these little tests I never tried to code a 3D application... I still do not have that knowledge.

 

I download Aggror's pdf and I will have a look over it. Thank you.

Share this post


Link to post

In terms of efficiency I'm not sure how things are handled in BMax but in C++ you would probably want to use something like a Map container which allows you to tag the object pointer with a text label and the pair are indexed by the label; making for fast and efficient retrieval.

 

Do you have a code for this in C++?

Share this post


Link to post

ok, this will be at least funny for you guys but: how do I "store" the pointer?

 

I tried this:

 

For Local e:TEntity = EachIn CurrentWorld().Entities

Select GetEntityKey(e, "Name")
    Case "a_1"
         MapInsert(map, "tree1", e)

    End Select
Next

 

but then I cannot "read" the info in no way..

Share this post


Link to post

Not sure if I understand you but if this helps

 

Global pos:TEntity

 

For Local e:TEntity = EachIn CurrentWorld().Entities

Select GetEntityKey(e, "Name")

Case "bg_pos"

pos = TEntity(e)

Share this post


Link to post

@cassius: if I am doing that I will just copy the "bg_pos" entity to the Pos entity, but I will not be able later to move that object for example. I will need to search again through all...

Share this post


Link to post
Guest Red Ocktober

i took a slightly different approach to finding "objects" (using BlitzMax, but code and logic is simple enough to translate to c++), though it is basically similar to the one suggested above...

 

the first thing i did was to make my BlitzMax code aware of the lua framework...

 

'To create a new lua-gluefunctions.bmx file, comment and uncomment the following lines.
Include "lua-gluefunctions.bmx" '--Comment this line out to create new lua-gluefunctions.bmx
'Import lugi.generator		 '--Uncomment this line to create new lua-gluefunctions.bmx
'GenerateGlueCode("lua-gluefunctions.bmx") '--Uncomment this line to create new lua-gluefunctions.bmx
'Notify("All Done", 0)					 '--Uncomment this line to create new lua-gluefunctions.bmx
'End

...
...

' Create framework 'fw''
Global fw:TFramework = CreateFramework()
If Not fw RuntimeError "Failed to initialize engine."

' Pass to the lua state'
SetScriptObject("fw", fw)

 

then, i find the submarine in my .sbx map (instead of searching the world, i search the map) with the following simple function...

 

Function FindChild:TEntity(scene:TEntity, name:String)
 For Local entity:TEntity=EachIn scene.kids
   If entity.getkey("name","")=name
     Return entity
   EndIf
 Next
End Function

 

and then before the main loop call the function to get the object and position it slightly above level in the editor...

Local theSub:TEntity=FindChild(scene,"type232s_1")
MoveEntity theSub,Vec3(0,2,0)

 

the, in the main loop i can move the object...

moveEntity theSub,Vec3(0,0,-.06*AppSpeed())

 

i think this is the simplest way to do what you're looking to do (a simple procedural approach), and i'm sure you can rotate the object without resorting to physics bodys and forces (depending on the type game you're making) to make the mesh move in whatever direction you wish...

 

the key part here is exposing the lua scripted objects and states to the BlitzMax code...

 

i hope this helps...

 

--Mike

Share this post


Link to post

@Red Ocktober: thanks mate. this "findChild" function is perfect. For now I think this is enough..

 

After I load the scene, I need to manipulate some objects, not many, so this might be ok.

Share this post


Link to post

if I am doing that I will just copy the "bg_pos" entity to the Pos entity, but I will not be able later to move that object for example. I will need to search again through all...

 

I don't know Blitzmax, but in the C/C++ version of LE2 every TEntity, TModel, TMesh, TWhatever is just a pointer.

That means you are not creating a copy of the actual thing, just a copy of the pointer to it.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...