Page 1 of 1
LuaState question [Solved]
Posted: Wed Mar 04, 2015 5:46 pm
by jedimoose32
Hi everyone.
I've done a very small amount of Lua coding before. For my current mod project I'll need to do a fair amount. Before I dive into it, I'd like to clarify one thing that I've wondered about for a while.
In the Lua Callback Reference list
HERE, there's a whole list of functions that the game accepts. I understand how to use a lot of them but there's one way of using certain ones that I've seen a lot that I really don't get. Here's an example from the teleport sample code (not Zerted's):
Code: Select all
function MoveEntityToNode(entIn,pathIn,nodeIn)
Just to be clear, I'm not trying to make a teleporter - I only used that example because it was one of the first I could find. My understanding is that MoveEntityToNode allows the Lua code to access information that is inside of the C code the game engine is using, and that entIn, pathIn, and nodeIn are variables. What I don't understand is how I/we know the names of those variables, and in what order they need to be called. Here's another example, something I was helping JazzMaster with:
Code: Select all
onvehkill = OnObjectKill(
function(object, killer)
if IsCharacterHuman(killer) and GetEntityClass(object) == GetEntityClassPtr("imp_hover_speederbike") then
counted_points = counted_points + 1
end
end)
How do we know that these variables are called object and killer, and how do we know that they aren't supposed to be called in the reverse order (i.e. function(killer, object))?
Thanks in advance. I know there's probably an obvious answer I'm missing.
Re: LuaState question
Posted: Wed Mar 04, 2015 9:22 pm
by GAB
jedimoose32 wrote:My understanding is that MoveEntityToNode allows the Lua code to access information that is inside of the C code the game engine is using, and that entIn, pathIn, and nodeIn are variables. What I don't understand is how I/we know the names of those variables, and in what order they need to be called.
I think those names are mere placeholders to describe the nature of the value that goes there. Their order was figured out by trial and error I'd guess.
jedimoose32 wrote:Code: Select all
onvehkill = OnObjectKill(
function(object, killer)
if IsCharacterHuman(killer) and GetEntityClass(object) == GetEntityClassPtr("imp_hover_speederbike") then
counted_points = counted_points + 1
end
end)
How do we know that these variables are called object and killer, and how do we know that they aren't supposed to be called in the reverse order (i.e. function(killer, object))?
The document
battlefront2_scripting_system shows what the names and orders are for a bunch of functions. I believe that's where we learned these orders and names. You should probably read it if your going to go into scripting.
Re: LuaState question
Posted: Wed Mar 04, 2015 9:44 pm
by jedimoose32
You're right, that doc is pretty helpful. Thanks!
I can't believe I fell victim to the classic "didn't check the documentation first" blunder... 
Re: LuaState question [Solved]
Posted: Fri Mar 06, 2015 2:54 am
by [RDH]Zerted
The parameter/argument/variable names mean nothing. You can name them anything and it'll still work as long as you're consistent. It's the positions that matter. First parameter, second parameter, etc... It's a
very common mistake people make when new to programming.
As for determining what they are, you read it in the documentation or look how the retail code uses the functions. If there are no example, then it can be very difficult to figure out how to use them. I think there are examples for almost every function. But developers normally follow a convention. Such as all the Set/Get functions behaving in a similar way and all Is**** functions are boolean checks that return true or false. You can use hints like that to guess at their parameters. You could also use a hex editor and try to locate where the function is defined within the exe.
Here's an almost complete listing of all available ingame functions:
Re: LuaState question [Solved]
Posted: Fri Mar 06, 2015 3:00 am
by jedimoose32
That makes sense. I'm assuming the best way to check for the retail usage of certain functions is to... use a hex editor?
Thanks for that list by the way!
Re: LuaState question [Solved]
Posted: Fri Mar 06, 2015 7:49 pm
by [RDH]Zerted
No, use a tool to search through all of the asset and documentation files at the same time. Something like grep, my example finder, Window's indexing service, etc... Unless you really want to learn hex editing.
I've done everything I did without hexes, curses, or charms

Re: LuaState question [Solved]
Posted: Fri Mar 06, 2015 7:50 pm
by Marth8880
Oh, by the way, Zerted, your Example Finder no longer works since Java 1.8 was released.
Re: LuaState question [Solved]
Posted: Fri Mar 06, 2015 8:03 pm
by jedimoose32
[RDH]Zerted wrote:I've done everything I did without hexes, curses, or charms

I notice you didn't say anything about spells...
And yeah I have had trouble with the example finder since the update as well.

Re: LuaState question [Solved]
Posted: Sat Mar 07, 2015 5:58 pm
by hunpeter12
Strange. I also have the latest version of Java, yet I don't have any trouble with Example Finder.
Re: LuaState question [Solved]
Posted: Sat Mar 07, 2015 6:06 pm
by jedimoose32
Mine works sometimes, and other times it doesn't. Like for example I'll try to use it and when I try to press the buttons they don't do anything.
Re: LuaState question [Solved]
Posted: Sun Mar 08, 2015 7:58 pm
by Marth8880
You guys probably have both versions installed.
Re: LuaState question [Solved]
Posted: Sun Mar 08, 2015 8:00 pm
by jedimoose32
If you mean both 32-bit and 64-bit then yes. Otherwise... I'm not sure and I'd have to check yo see whether I have somehow managed to get a redundant Java installation on my machine.
Re: LuaState question [Solved]
Posted: Sun Mar 08, 2015 8:21 pm
by Marth8880
I mean 1.7 and 1.8.
Re: LuaState question [Solved]
Posted: Sun Mar 08, 2015 8:52 pm
by jedimoose32
Nope. I just had a look and I actually only have 1.8, as far as I can tell.
Re: LuaState question [Solved]
Posted: Mon Mar 09, 2015 1:22 am
by [RDH]Zerted
I don't have enough HDD space available right now to install Java 8 and test it. Though I don't have a clue as to why it would stop working. Thanks for letting me know about it.