Jump to content

Lua : access to variables


YouGroove
 Share

Recommended Posts

Wel i have a several questions :

 

-When Loading a world in Lua , does it loads the entities also and their script or do we have to create them by code and place them

in the world loaded by code ?

 

- It is possible to detect in LUA a collision tha returns what otehr entitie is collided (like a dynamic one , like a character) ?

By raycast ? by volume detection collision ?

 

-It is possible in Lua to access other entities Lua variables after laoding a level.

For example i made some NPC character i placed in the editor that has the variable "Life" for example.

My main Lua script will have some function to load the level than manage a Third view controler , when i fire a weapon for example,

It is possible to manage in Lua to retriev this variable "Life" of the other entitie and decrease it ?

And after reaching zero, play death animation on otehr entitie ?

Stop toying and make games

Link to comment
Share on other sites

1) loadscene loads the model's mesh (with its material if it has one), script (if it has one), and PHY body (if it has one, if not creates a static one)

2) yes by collision

3) yes

 

also please post programming questions in the appropriate forum board.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

About your 3rd question here is what I've been doing.

 

1) Create a model that represents a character (or whatever)

 

2) Create a lua script for that model and in that scrip add variables specific to it:

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

 

3) Then in my main lua game file is where I create these models (although you could place them at design time also). I then either loop through a list I've stored the models in or if I pick with the mouse the entity to get the model which then you can use:

 

objecttable[model].health = 20

 

So once you get a variable pointing to a model you can use it as a key to the objecttable table to get those model specific variables.

Link to comment
Share on other sites

Thanks Rick !

In fact i really wanted t oavodi the "get Models" from the scene :)

I thaught they could just interact between them and the player only by their "attached" scripts !

For example in the editor i place a model where i put the player code (Camera view, atacking code , collision with other entities etc ...)

Than i put in the level some ennemies, i attach to each of them some action like "if player near -> attack ; if life to 0 , fall animation then remove from world)

I thaught the main function would only be used to initialize the engine, laod the world, and manage menus or level changing.

 

In fact it is same as with C# or C++ where you must lookup for all entities you have placed in the world than call the good code appropritae to the enity type ?

 

I'll try it tonight.

Perhaps it can be the other way, of placing all modes on the world editor and their code.

Then just make a simple main to load the level ready to play without having to care about entities because their code have been edited from the world editor !

Stop toying and make games

Link to comment
Share on other sites

Yeah, you can do that also. Just note you'll have to tell the AI scripts who the "player" is.

 

If you look here -> http://www.leadwerks.com/werkspace/files/category/6-scripts/ and look for things that start with Pi-, this is the route I was taking some time back. It was all script attachment based with one variable I think in the main script to tell if we were in design mode or gameplay mode since everything you put in Update() will run no matter what mode you are in and sometimes you wouldn't want that. Like in your example you probably wouldn't want your AI running around when in design mode.

 

To let the AI scripts "know" who the player is you could use the link system (although that might get to be a pain to have to link the player to each enemy) or you could create a custom property that holds the name of the player object you have.

 

You can see some examples I've done in the past with Pi- scripts where a small little demo is entirely done in model scripts (or what I call Thingoids)

 

Link to comment
Share on other sites

Thanks a lot Rick !

 

I'll dig and test these examples tonigh.

Yes i will put a variable to stop NPC attacking in level editing mode indeed, or it will be a real warfare battle with NPC and me trying to adjust the level :) !

 

you could create a custom property that holds the name of the player object you have.

 

Some engines proposes something similar to this , and this is what i'll choose.

For example the name will simply be : "PLAYER" it wil lhave all player things , propeties , collision stuff etc ...

Stop toying and make games

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...