I was under the impression that this should only happen once, when the player ship docks. From the documentation it seems possible that it is called for every ship that docks. However, for example the "package delivery" mission script which I still use as a formal template, does not check whether the ship that called onCreateBB is the player ship.This event is triggered the first time a Ship docks with the station or is placed directly into the station (eg by Space.SpawnShipDocked or at game start)
Now I don't know exactly where the problem is: If it is intended for onCreateBB to be called whenever a ship docks with a station, I'd suggest to update the documentation to make that fact clearer, and to modify existing mission scripts to check for player before adding adverts. Anything else would seem a waste of resources.
Or if, which would seem more logical, onCreateBB is indeed only intended to be called when the player docks, I'd suggest to fix the code.
I am not sure if the problem is that onCreateBB is called for every docking, however, it is clear that it is called several times, and as far as I could tell perpetually. Here's the script I used, it simply throws out a message on every onCreateBB:
Code: Select all
local systemiter = 0
local onCreateBB = function (station)
--local num = Engine.rand:Integer(0, math.ceil(Game.system.population))
-- for i = 1,num do
debugmessage = string.interp("onCreateBB call {num}", {num = systemiter,})
Comms.ImportantMessage(debugmessage, "debug")
systemiter = systemiter + 1
-- end
end
local serialize = function ()
return { ads = ads, missions = missions }
end
local unserialize = function (data)
loaded_data = data
end
Event.Register("onCreateBB", onCreateBB)
Mission.RegisterType('UB_RoboSurvey','Robotic Survey')
Serializer:Register("Robotic Survey", serialize, unserialize)