• Advertisement
Sign in to follow this  

weird problem calling functions in LUA.

This topic is 4979 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Incredible, you were right Object is nil, but the function is being called using Object instance :(. Why could be this?.

Thanks in advance,
HexDump.

Share this post


Link to post
Share on other sites
I´m trying to execute core code from C with loadstring instead of using dostring, but loadstring seems not to exist :?. What's up?.


Thnakns in advance,
HexDump.

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={Enemy,Enemy,Enemy}

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}
end

enemyList={NewEnemy("Bob",{0,0,0},100),NewEnemy("Jimmy",{0,0,0},100)}

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()
Instance={Speed=0;Enabled=0;Life=0;DoLogic=0;ID=0;}
Enemies[nNextEnemyID]=Instance;
nNextEnemyID=nNextEnemyID+1;
end;

->Now I load all IA functions and bound them to the objects
->The IA functions are load with DoString too
Enemies[nNextEnemyID-1].DoLogic=ScannerLogic;

->But when I do this, I have checked that Enemies[1] is nil
Enemies[1].DoLogic(Enemies[1]);


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement