Page 1 of 1
onLeaveCombat event usage?
Posted: Sun Aug 15, 2010 1:04 pm
by TheDarkSide
Hmm so I would like to know how much code can you exactly put between those <onLeaveCombat> tags in your profile... I tried to create a function there but I just get the following error when trying to run the bot:
Code: Select all
../rom/settings.lua:612: Failed to compile and run Lua code for onLeaveCombat in character profile.
The code I put there basicly looks like this:
Code: Select all
<onLeaveCombat><![CDATA[
function myFunction()
local condition = getConditionStatus();
if(condition == nil) then
return false
else
return true
end
end
]]></onLeaveCombat>
My function consists about 200 lines of code so I became wondering whether the LuaCode buffer can hold that much data... Or it can just be some primitive parsing error in my code which gives that error...
Or is it that you can't create functions there? Only call already declared ones? Well whatever the problem is it would be very much appreciated if someone could solve it.
Ps. Tried to search forums for similar topics but it gave me some 91 or 0 results with different keywords so feel free to redirect me to the thread which concerns this problem if such thread already exists.

Re: onLeaveCombat event usage?
Posted: Sun Aug 15, 2010 2:07 pm
by TheDarkSide
Okay I realized that you can only use the functions that are listed in rombot wiki between those tags so I created the userfunctions.lua in rom folder and put my function there.. Now I just call that function in that onLeaveCombat event... But again I got error message...
Code: Select all
.../micromacro/scripts/rom/classes/player.lua:1012: Error in your profile: onLeaveCombat error: [string "..."]:3: attempt to call global 'MyFunction' (a nil value)
I think this means my function is out of scope (though I thought bot.lua automatically includes userfunctions.lua if such file exists) or it returns a nil value... Of course I could maybe edit the functions.lua and put the function there but I think it would be patched when I run SVN updates...
So where can I actually put my function and where to call it when I want it to be executed everytime player leaves combat?
EDIT: I had a typo in userfunctions.lua's filename so I fixed it and now my function should be included in the bot.lua and therefore calling it in the onLeaveCombat event should trigger it but again that same
onLeaveCombat error: [string "..."]:3: attempt to call global 'MyFunction' (a nil value) error occurs... All the parse errors from my function have now been fixed since Micromacro told me on which line which symbol was expected... Not actually sure what goes wrong...
Now it looks like this in my profile:
Code: Select all
<onLeaveCombat><![CDATA[
myFunction(); -- call the function I put in userfunctions.lua
]]></onLeaveCombat>
Ps. myFunction is not really the name of the function.. I just use it as an example.
Pps. Lua is not my 1st coding language so my questions might sound noobish.. Thank you for your patience.
Re: onLeaveCombat event usage?
Posted: Sun Aug 15, 2010 7:49 pm
by Administrator
You know, unless you actually let us know what you put in userfunctions.lua, there's not very much anybody can do.
I just hope you didn't do something like name the file userfunctions.lua.lua.
Re: onLeaveCombat event usage?
Posted: Mon Aug 16, 2010 5:59 am
by TheDarkSide
Alright I'll post the actual code but I think I'll make a new topic of it then since it might actually be pretty useful function and some people have been requesting it... I'll just make a few modifications to it..
But I'm not sure whether it is the function I made that fails... I think the function call fails somehow as if it actually went to execute the code in my function, it wouldn't very likely drop such execptions as I've been reading from the screen... And my function doesn't return nil values... (only true or false) so I think that (a nil value) doesn't mean the function returned nil, more like it wasn't even executed or something...
And nope the file name is now correct (userfunctions.lua) and the bot compiles it properly but just the actual calling of the function inside that file doesn't seem work...
EDIT: it seems that the function call now succeeds... Now I just need to make my function fully functional ^^