Page 1 of 1
Executing lua code after waypoints file load
Posted: Mon Nov 30, 2009 3:31 am
by x_art
Is it possible to execute a lua code after waypoints file load? Situation: I harvest resources in different locations. I would to change some profile options (harvest range for example) for each location. I can put this code within a waypoint, but the bot can start from any waypoint and therefore the option will be changed after some time. I can create a different profile for each location, but this requires multiple identical profile files.
Re: Executing lua code after waypoints file load
Posted: Mon Nov 30, 2009 9:33 am
by Administrator
You could put it in your profile's onLoad event. You'll just have to check which file is loaded.
Code: Select all
<onLoad><![CDATA[
local wpname = settings.profile.options.WAYPOINTS;
if( settings.profile.options.PATH_TYPE == "waypoints" ) then
if( wpname == "whatever1" ) then
-- do stuff for waypoint list #1
elseif( wpname == "whatever2" ) then
-- do stuff for waypoint list #2
else
-- default stuff
end;
end
]]</onLoad>
The problem with this is that it reads directly out of the profile which waypoint list to look for and will not be affected by forced profile changes (by using path:whatever in the command line).
Re: Executing lua code after waypoints file load
Posted: Mon Nov 30, 2009 9:41 am
by x_art
Administrator wrote:You could put it in your profile's onLoad event. You'll just have to check which file is loaded.
The problem with this is that it reads directly out of the profile which waypoint list to look for and will not be affected by forced profile changes (by using path:whatever in the command line).
Thank you for this solutions that is more useful in my case. But I think that this solution will not work I'll load waypoitnts from a code with help of loadPaths("") function. Will be the onLoad event triggered at this time?
Re: Executing lua code after waypoints file load
Posted: Mon Nov 30, 2009 9:55 am
by Administrator
onLoad is triggered when a profile is loaded, not a waypoint file, so no. You can, however, use loadPaths() within this segment and it will override the normal waypoint loading so you can accomplish what you want. The only real change to the code I posted earlier is that you need to add loadPaths(wpname, settings.profile.options.RETURN_PATH) right under the line that sets wpname.