you've done great vvith it so far! You're not done porting though, here's some things you still need to fix:
- Those variables at the start are basically locals, as C frees them at the end of the function instead of piling them up into a memory leak. In lua, you need to add a
local
keyword to recreate this behavior, and prevent srb2 from throwing a fit about globals.
- Again with those variables at the start, types in lua are part of what is stored in a variable, and can be read with the type() function. In short, you don't define locals/variables in lua with a type like in c, and the
var
keyword needs to be used instead to define a variable regardless of type. Here's what one should look like: local var zoffs = 0
- C uses a ; to define a new line of code/the end of an instruction. Actually using it as a full replacement for line breaks makes code litterally unreadable, so the srb2 programmers made sure to always include both. Lua just uses the line breaks to define this, so there's no need for them anymore. I don't know if ;s parse under lua, but it's probably best to assume it doesn't.
- slade is recognizing
add
as something that exists, seeing by the yellow text. You might be overwriting a global function or something, so rename add
and all instances of it here to fix that.
- MT_WHIPTAIL is an integer value, and can't really be for-looped. You should try using the "MobjThinker" hook to replace it. At the bottom of this function, you'll see this:
end)
. To make the hook run specifically for all MT_WHIPTAIL objects, do this; end, MT_WHIPTAIL)
It makes more sense if you do what i do and store the function as a local instead of storing the entire function in the addHook function. Both are valid though.
- I get the feeling you removed the comment on
initial position...
, whatever the case it will throw an error in both languages, so either check the c function again or put the //
back
P_SetMobjState(mobj, state);
is replaced in lua with editing the state value directly, like this: mobj.state = state
chosenstate
and some other variables are given their proper value by the end, but aren't used to set anything that affects the actual object. Try checking the C function again, or reimplement them based off of their names.
I know the list looks intimidating, and it's probably because it is. A lot of errors I've seen here look like inexperience with just lua, but you're still learning, and a lot by what I can tell! It's probably best that you try to avoid porting functions until you get more comfortable with lua and scripting in general. There are other ways to get around that original problem, such as actively avoiding using tails at all, or inserting the tails back in the sprites you're using. You might want to focus on eclipse's other abilties for now, and if you really can't get around this problem, just quote me or something to get my attention.