Hey there.
I am sending via msg.post() a message from one to another script. now I have an example where it looks like the receiving script is getting a couple of messages sometimes.
This is the sending script:
for v,i in ipairs(GLOBAL.units) do
msg.post(GLOBAL.units[v].id, "upgrade", {researchNo = self.isresearching})
print("STRUCTURE: Sending upgrade to unit " .. GLOBAL.units[v].id)
end
This is the receiving script:
if message_id == hash("upgrade") then
GLOBAL.researchType[message.researchNo].exec(self)
msg.post("main:/gamecam#playerstats", "floatingtext", {text = GLOBAL.researchType[message.researchNo].name .. "\n+ " .. GLOBAL.researchType[message.researchNo].researchValue, pos = self.pos, color = GLOBAL.COLOR_ORANGE, fadespeed = 0.5})
print(self.unit.instanceID .. " " .. self.unit.name .. " upgraded " .. GLOBAL.researchType[message.researchNo].name)
end
The function() called at the receiving script is from a table (GLOBAL.researchType) like this:
{
hash = hash("moreAmmo"),
name = "Increase unit magazine",
description = "Increases ammount of ammo for each unit",
researchResource = "iron",
researchCost = 400,
researchTime = 3, -- Seconds
researchValue = 5,
researchGroup = "unit",
exec = function(self)
self.unit.ammoMagazine = self.unit.ammoMagazine + 5
end
}
Dont have an idea why this happens. If I just got a few units it works. But if I have -lets say- more than 10 this happens:
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance17]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance18]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance19]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance20]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance21]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance22]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance23]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance24]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance25]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance26]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance27]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance28]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance29]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance30]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance31]
DEBUG:SCRIPT: STRUCTURE: Sending upgrade to unit [/instance32]
DEBUG:SCRIPT: [/instance17] Buggy upgraded More unit movespeed
DEBUG:SCRIPT: [/instance28] EMP Launcher upgraded More unit movespeed
DEBUG:SCRIPT: [/instance29] Constructor upgraded More unit movespeed
DEBUG:SCRIPT: [/instance27] Tank upgraded More unit movespeed
DEBUG:SCRIPT: [/instance21] Rocketlauncher upgraded More unit movespeed
DEBUG:SCRIPT: [/instance25] Collector upgraded More unit movespeed
DEBUG:SCRIPT: [/instance25] Collector upgraded More unit movespeed
DEBUG:SCRIPT: [/instance27] Tank upgraded More unit movespeed
DEBUG:SCRIPT: [/instance25] Collector upgraded More unit movespeed
DEBUG:SCRIPT: [/instance32] Tank upgraded More unit movespeed
DEBUG:SCRIPT: [/instance27] Tank upgraded More unit movespeed
DEBUG:SCRIPT: [/instance28] EMP Launcher upgraded More unit movespeed
DEBUG:SCRIPT: [/instance29] Constructor upgraded More unit movespeed
DEBUG:SCRIPT: [/instance30] Agent upgraded More unit movespeed
DEBUG:SCRIPT: [/instance32] Tank upgraded More unit movespeed
DEBUG:SCRIPT: [/instance32] Tank upgraded More unit movespeed
The first lines are ok, these are the SENDING lines, but why the hell are some units / instances are upgrading more than one time (f.e. /instance25 are 3 times)?
Any ideas? how to fix this?