Script.SetWatchWeapon + ProjectileCreated

Script.SetWatchWeapon + ProjectileCreated

Discuss your problems with the latest release of the engine here. Problems with games, maps or other utilities belong in their respective forums.

Moderator: Moderators

Post Reply
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Script.SetWatchWeapon + ProjectileCreated

Post 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
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Script.SetWatchWeapon + ProjectileCreated

Post by Anarchid »

Try without Script?
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: Script.SetWatchWeapon + ProjectileCreated

Post by PepeAmpere »

does nothing :) it doesnt react any projectile :)

Code: Select all

function gadget:ProjectileCreated(projectileID, projectileOwnerID, projectileWeaponDefID)
	Spring.Echo(projectileWeaponDefID)
end
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: Script.SetWatchWeapon + ProjectileCreated

Post 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)
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: Script.SetWatchWeapon + ProjectileCreated

Post 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?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Script.SetWatchWeapon + ProjectileCreated

Post by jK »

check where it is located on the wiki
and note, you didn't mentioned the important thing here that makes it fail.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Script.SetWatchWeapon + ProjectileCreated

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Script.SetWatchWeapon + ProjectileCreated

Post 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?)
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: Script.SetWatchWeapon + ProjectileCreated

Post by PepeAmpere »

yes, it seems thats what great person is trying to suggest.
Post Reply

Return to “Help & Bugs”