Sign in to follow this  

weird problem calling functions in LUA.

Recommended Posts

Hello, I´m having a weird problem I can´t solve. I have a function in LUA, this is: function DoLogic() Enemies[1].DoLogic(Enemies[1]); end That calls this other function: function ScannerLogic(Object) CnMoveObject(Object.ID,-1,0,0); end DoLogic Member is assigned ScannerLogic() at runtime. Well the problem is that when ScannerLogic is called, the computer hangs up with a violation error. If I change CnMoveObject(Object.ID,-1,0,0); by CnMoveObject(1,-1,0,0) I mean a hardcoded value everything works well. I think it has something to do with the function assigment, but don´t know. Thanks in advance, HexDump.

Share this post

Link to post
Share on other sites
Check if Object in ScannerLogic is nil. This could happen if you forgot to use : instead of . somewhere. (e.g. calling Enemies[1]:DoLogic(); is the same as calling Enemies[1].DoLogic(Enemies[1]);)

Share this post

Link to post
Share on other sites
The problem could be the way you instance your enemies. This would be the wrong way:

Enemy = {name="Default Name",position={0,0,0},skill=100}


enemyList[1].name = "Bob"
enemyList[2].name = "Jimmy"

This is the correct way:

function NewEnemy(enemyName,enemyPosition,enemySkill)
return {name=enemyName,position=enemyPosition,skill=enemySkill}


Share this post

Link to post
Share on other sites
Everything, tables and funcions are pushed from C to Lua
using dostring.

I create a new enemy using:

->This function is pushed to Lua with DoString.
function MakeEnemy()

->Now I load all IA functions and bound them to the objects
->The IA functions are load with DoString too

->But when I do this, I have checked that Enemies[1] is nil

Really weird.

Edited: I have ran the code using LUAIDE and Enemies[1] seems to be ok, not nil :(. Does it has anything to do with DoString?.
I would like to use LoadString, but when I use it the compilers says that it is an undeclared identifier :(. I´m desesperated.

Thanks in advance,

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this