Jump to content

Beginner LUA question


Pants
 Share

Recommended Posts

Just starting to learn LUA scripting, thanks to Aggrors tutorials.

 

Is it possible to pick an object and have the object execute a function? Can I camera pick a door, and have the door run it's own object:open() method? And if so, how? I know this can be done using SendMessage and ReceiveMessage, but I need to pass more variables than those will allow (lua types, to be specific).

 

Thanks.

DualCore E6500 @ 2.9GHz / 3GB / GForce GTX 460 / XPSP3

Link to comment
Share on other sites

Look at how the switch and underground_fanblades scripts work. Also open up the tunnels.sbx file and you will see an example of them working.

 

As far as I can tell, this example uses messages..

DualCore E6500 @ 2.9GHz / 3GB / GForce GTX 460 / XPSP3

Link to comment
Share on other sites

As far as I can tell, this example uses messages..

 

Hi, you can use something like this

require("scripts/utilities")
...
local pick=CameraPick(fw.main.camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,2.0),0,0)
if pick then
    local pickedmodel=GetMeshModel(pick.entity)
    objecttable[pickedmodel]:open()
end

Link to comment
Share on other sites

Thanks Soamp, that works perfectly!

I'm not sure how the objecttable works, but I'm sure I'll learn.

 

 

Aggror, the door:open() was an example just to illustrate my problem. To be specific, if my player character is punching another character, so I need to pick the enemy, and have it run a GetHit() function, the parameter passed needs to be a Lua type holding my character object's rpg-style skill variables, like player.attribute_strength, player.skill_unarmed, and so forth. The problem I was having is that you can not pass lua types as the extra parameter in SendMessage, all it allows is the message, delay, and an extra string.

 

The solution Soamp suggested is exactly what I needed, thanks again.

DualCore E6500 @ 2.9GHz / 3GB / GForce GTX 460 / XPSP3

Link to comment
Share on other sites

Thanks Soamp, that works perfectly!

I'm not sure how the objecttable works, but I'm sure I'll learn.

 

sorry for the misdirect, I didn't understand exactly what you were trying to accomplish...

 

but in any case, you should probably read Getting Started with Lua... specifically page 10 concerning Classes and Objects.

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

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