Page 1 of 1

Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 05:21
by PepeAmpere
I found this script Script.SetWatchWeapon(weaponDef.id, true) is something like prerequisite for use of Call-in ProjectileCreated, where i can match the same weaponDef.id.

I did this in init part:

Code: Select all

function gadget:Initialize()    
	for id,weaponDef in pairs(WeaponDefs) do
		local wName = weaponDef.name
		if (wName == "darkswarm") then
			Script.SetWatchWeapon(weaponDef.id, true)
			bugWeaponID = weaponDef.id
		end
	end
end
And I plan to use something like this (bugWeaponID is global):

Code: Select all

function gadget:ProjectileCreated(projectileID, projectileOwnerID, projectileWeaponDefID)
	if (bugWeaponID == projectileWeaponDefID) then
		spSetUnitWeaponState(projectileOwnerID,2,"range",100)
	end
end
.. but when gadget is loaded, i get this error:
[f=0000000] Error: error = 2, LuaRules/draw.lua, error = 2, LuaRules/gadgets.lua, [string "LuaRules/Gadgets/0fix_bug5.lua"]:56: attempt to call field 'SetWatchWeapon' (a nil value)
Can you pls explain how this work and if this Script is the one i need for use of this call-in described on wiki like:
ProjectileCreated() --> "proID, proOwnerID, weaponDefID" Only called for weapons with SetWatchWeapon enabled

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 08:10
by Anarchid
Try without Script?

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 16:40
by PepeAmpere
does nothing :) it doesnt react any projectile :)

Code: Select all

function gadget:ProjectileCreated(projectileID, projectileOwnerID, projectileWeaponDefID)
	Spring.Echo(projectileWeaponDefID)
end

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 16:46
by jK

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 17:09
by PepeAmpere
thx for link, but how this answers the main point of question, why the gadget load fails?
PepeAmpere wrote:

Code: Select all

function gadget:Initialize()    
	for id,weaponDef in pairs(WeaponDefs) do
		local wName = weaponDef.name
		if (wName == "darkswarm") then
			Script.SetWatchWeapon(id, true)
			bugWeaponID = id
		end
	end
end
.. but when gadget is loaded, i get this error:
[f=0000000] Error: error = 2, LuaRules/draw.lua, error = 2, LuaRules/gadgets.lua, [string "LuaRules/Gadgets/0fix_bug5.lua"]:56: attempt to call field 'SetWatchWeapon' (a nil value)
Btw, the id of weaponDef used as "script" parameter is 292 :-) (=its defined)

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 17:23
by PepeAmpere
Ok, can be the reason for this error the fact, i found another use of this Script.SetWatchUnit for the same weapon in different gadget?

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 18:20
by jK
check where it is located on the wiki
and note, you didn't mentioned the important thing here that makes it fail.

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 29 Jul 2013, 20:32
by FLOZi
jK wrote:check where it is located on the wiki
and note, you didn't mentioned the important thing here that makes it fail.
Image

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 30 Jul 2013, 00:37
by knorke
do you have a

Code: Select all

if (not gadgetHandler:IsSyncedCode()) then blub
in gadget?
So that SetWatchWeapon is not called in unsynced part, where it might not exist. (this might also be what jK means?)

Re: Script.SetWatchWeapon + ProjectileCreated

Posted: 30 Jul 2013, 01:25
by PepeAmpere
yes, it seems thats what great person is trying to suggest.