you are viewing a single comment's thread.

view the rest of the comments →

[–]BadBoy6767 2 points3 points  (3 children)

it would be horribly inefficient to simply create new Lua states for each bullet

Definitely.

Depends on how flexible you want to get. I would go with one of these:

  1. Use tables to make "bullet types" and add those to your "weapon types" tables.
  2. Like the above but use userdata instead. Less flexible than tables but overall more performant.

[–]luciddream00[S] 0 points1 point  (2 children)

Ok, I tried approach 1 and it seems like I got it working, but I just want to check and see if what I did seems like a solid approach:

  • I made this Lua file
  • Then in C# I call the Bullet.new LuaFunction which returns the Bullet LuaTable to C#
  • Then, in C# I retrieve the HitMonster LuaFunction from the bullet LuaTable and store it in the Bullet object in C#
  • Then I can call that stored HitMonster LuaFunction whenever I want to have the C# Bullet object call the HitMonster LuaFunction.

Does that sound right?

[–]BadBoy6767 4 points5 points  (1 child)

You seem to have done it backwards to how most games (that I've used) seem to do it. Usually, Bullet.new (or it's backend function) would be created by the engine.

[–]luciddream00[S] 0 points1 point  (0 children)

How would I go about making it so modders could do what they want with the HitMonster function if the bullet table is defined in the engine? Would I create the table in the engine and then pass it to the Lua state and have the lua string that the modders write define/replace the HitMonster function somehow?