errors

RawrRawr Posts: 508 Seed
edited February 2015 in Code
Hey,

Tired and lazy at this point. RecipeOperator.lua error482. Says attempt to index local object(nil value). Looked up the the file. Looks like it got stuck setting it's position.
...
My code is as follows:
include("Scripts/Objects/Equipable.lua")
include("Scripts/Mixins/Usable.lua")
include("Scripts/Objects/PlaceableObject.lua")

-------------------------------------------------------------------------------
if GourdWand == nil then
	GourdWand = PlaceableObject.Subclass("GourdWand")
end

-------------------------------------------------------------------------------
function GourdWand:Constructor(args)
	self.m_object1 = nil
end

-------------------------------------------------------------------------------
function GourdWand:PrimaryAction( args )
	if self.m_object1 == nil then
		return
	end

	if NKGetName(args.object) == "Gourd Fence" then
		args.object:RaiseClientEvent("ClientEvent_SetLinked", toPosition = NKGetWorldPosition(self.m_object1))
		self.m_object1:RaiseClientEvent("ClientEvent_SetLinked", toPosition = NKGetWorldPosition(args.object))
		self:ModifyStackSize(-1)
	end
end

-------------------------------------------------------------------------------
function GourdWand:SecondaryAction( args )
	if NKGetName(args.object) == "Gourd Fence" then
		self.m_object1 = args.object
	end
end

-------------------------------------------------------------------------------
EntityFramework:RegisterGameObject(GourdWand)

I bet it's something simple. I'll be working at it again tomorrow afternoon when I'm fresh.
Thank you for any pointers in advance =)
Programmer, designer, artist.

Comments

  • ZakeZake Posts: 216 Seed
    482 should be the line number where the error is if that helps.
    I think more than I say and say more than I do, but I do more than I used to and plan to continue.
    TUG modder (at least in the ounce of free time that occasionally flits by)
  • johnycilohoklajohnycilohokla Posts: 283 Developer
    Rawr wrote:
    Hey,

    Tired and lazy at this point. RecipeOperator.lua error482. Says attempt to index local object(nil value). Looked up the the file. Looks like it got stuck setting it's position.
    ...
    My code is as follows:
    include("Scripts/Objects/Equipable.lua")
    include("Scripts/Mixins/Usable.lua")
    include("Scripts/Objects/PlaceableObject.lua")
    
    -------------------------------------------------------------------------------
    if GourdWand == nil then
    	GourdWand = PlaceableObject.Subclass("GourdWand")
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:Constructor(args)
    	self.m_object1 = nil
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:PrimaryAction( args )
    	if self.m_object1 == nil then
    		return
    	end
    
    	if NKGetName(args.object) == "Gourd Fence" then
    		args.object:RaiseClientEvent("ClientEvent_SetLinked", toPosition = NKGetWorldPosition(self.m_object1))
    		self.m_object1:RaiseClientEvent("ClientEvent_SetLinked", toPosition = NKGetWorldPosition(args.object))
    		self:ModifyStackSize(-1)
    	end
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:SecondaryAction( args )
    	if NKGetName(args.object) == "Gourd Fence" then
    		self.m_object1 = args.object
    	end
    end
    
    -------------------------------------------------------------------------------
    EntityFramework:RegisterGameObject(GourdWand)
    

    I bet it's something simple. I'll be working at it again tomorrow afternoon when I'm fresh.
    Thank you for any pointers in advance =)

    Ok so your using custom Crafting Station, it need either an craft attach point (check stone furnace or crude workbench .obj model) or offsetOverride.
    (the offsetOverride is defined like spawnOffsetOverride and it replaces it, but it skips the craft attach point)
    My Blog
    jc.png
      yt.png  t.png  
  • RawrRawr Posts: 508 Seed
    still no. I'm not using a custom crafting station, just placing two items on the ground and hitting craft. I looked around in the Vine Club.txt and club.lua and couldn't see anything about offset or craft attach points. An attach point doesn't make a whole lot of sense to me at this point either because I'm only using .obj already in the game, I've just mucked around with their normals and wanting to give them give them different functions...
    Heres my Gourd Wand.txt
    GameObjects
    {
    
    	Equipable
    	{
    
    		Gourd Wand
    		{
    			Transform
    			{
    			}
    			Script
    			{
    				file = "Scripts/Objects/GourdWand.lua"
    				class = "GourdWand"
    				arguments
    				{
    					encumbrance = 0.15
    				}
    			}
    			
    			StaticGraphics
    			{
    				model = "Models/PlaceableObjects/Harvestables/woodStickForked.obj"	
    				dontCastShadows = 1.0
    				Diffuse
    				{
    					0 = "Character/Tools/gourd_wand.tga"
    				}				
    			}
    			
    			RigidBody
    			{
    				activePhysics = 1
    				mass = 1
    				friction = 5
    			}
    			
    			Equipable
    			{
    				name = "Gourd Wand"
    				minScale = 1.0
    				maxScale = 1.0
    				icon = "0clubThorns_TLV"
    				category = "Weapon"
    				tier = 2
    				creakingSound = "ItemCreak"
    				breakSound = "ItemBreak"
    				impactFailSound = "WoodDig"
    				durability = 240
    				durabilityCreakingPoint = 8.0
    				attackSpeedModifier = 1.5
    				maxStackCount = 1
    				resource = 0
    				
    				Equipment Slots
    				{
    					Weapon
    				}
    			}		
    		}
    	}
    }
    
    And heres my GoundWand.lua
    include("Scripts/Objects/Equipable.lua")
    include("Scripts/Mixins/Usable.lua")
    include("Scripts/Objects/PlaceableObject.lua")
    
    -------------------------------------------------------------------------------
    if GourdWand == nil then
    	GourdWand = Equipable.Subclass("GourdWand")
    end
    
    -------------------------------------------------------------------------------
    --Mixin
    GourdWand.StaticMixin(Usable)
    
    -------------------------------------------------------------------------------
    function GourdWand:Constructor(args)
    	self.m_object1 = nil
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:PrimaryAction( args )
    	if self.m_object1 == nil then
    		return
    	end
    
    	if NKGetName(args.object) == "Gourd Fence" then
    		args.object:RaiseClientEvent("ClientEvent_SetLinked", toPosition = NKGetWorldPosition(self.m_object1))
    		self.m_object1:RaiseClientEvent("ClientEvent_SetLinked", toPosition = NKGetWorldPosition(args.object))
    		self:ModifyStackSize(-1)
    	end
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:SecondaryAction( args )
    	if NKGetName(args.object) == "Gourd Fence" then
    		self.m_object1 = args.object
    	end
    end
    
    -------------------------------------------------------------------------------
    EntityFramework:RegisterGameObject(GourdWand)
    
    So yea, I'm either failing at the game of spot the difference in how it's being done in vanilla or something else is at play.
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla Posts: 283 Developer
    hmm... ok.
    Does /spawn "Gourd Wand" work?
    Also can use post your crafting recipes? And the full error?

    RecipeOperator is related to crafting but line 482 can only be object related.
    Maybe it's a typo in the result name?
    My Blog
    jc.png
      yt.png  t.png  
  • RawrRawr Posts: 508 Seed
    GOT IT!
    when RaiseClientEvent() gets called it needed the string and for the next variable to be a dictionary (not sure if thats the right term for it in lua... maybe table? the '{}' )
    /spawn (Y)
    crafting with the objects (Y)
    Now, can't seem to pick it up. lemme muck around with it a bit longer but I'll post an update if I need more help.
    Programmer, designer, artist.
  • RawrRawr Posts: 508 Seed
    Ok, here's something that I'm puzzled over.
    Within my mod the Gourd fence gets saved between sessions but the Gourd wand doesn't... like what? Both objects are able to be crafted within the game and yet one manages to not be there next time I enter the world. What could be going on here?
    I remember Johny saying to me that sometimes I might need to fully restart the game, alas I've tried that here already. What are my other avenues to explore?

    edit:
    Here's my updated code if it's any help to someone.
    Gourd Fence - The one that does save
    The txt file
    GameObjects
    {
    	PlaceableObject
    	{
    		Gourd Fence
    		{
    			Transform
    			{
    			}
    
    			Script
    			{
    				file = "Scripts/Objects/GourdFence.lua"
    				class = "GourdFence"
    				arguments
    				{
    					encumbrance = 1
    				}
    			}
    
    			StaticGraphics
    			{
    				model = "Models/PlaceableObjects/Refined/fence_section.obj"
    				Diffuse
    				{
    					0 = "Models/PlaceableObjects/Refined/fence_section_gourd_diff.tga"
    				}
    			}
    			RigidBody
    			{
    				activePhysics = 1
    				mass = 2.0
    				friction = 5.0	
    			}
    			Placeable
    			{
    				name = "Gourd Fence"
    				icon = "fence_section"
    				minScale = 1
    				maxScale = 1
    				placementSound = "WoodPlace"
    				removalSound = "WoodDig"
    				miningEmitter = "Strike WoodHard Emitter"
    				miningEmitterAlt = "Strike GrassC Emitter"
    				category = "Fence"
    				tier = 0
    				resource = 1	
    				placeWithNoPhysics = 1
    				tetherDistanceModifier = 2.0
    				survivalRotOffset = [0.0, 1.0, 0.0, -90.0]
    				survivalPosOffset = <0.0, 0.0, 0.0>
    				survivalFaceCamera = 1
    				maxStackCount = 10
    			}
    		}
    	}
    }
    
    The Lua file
    include("Scripts/Interactable.lua")
    include("Scripts/Objects/PlaceableObject.lua")
    
    -------------------------------------------------------------------------------
    GourdFence = PlaceableObject.Subclass("GourdFence")
    
    -------------------------------------------------------------------------------
    --Register Events
    NKRegisterEvent("ClientEvent_TeleportToLinked",
    	{
    	playerToAffect = "gameobject"
    	}
    )
    
    NKRegisterEvent("ClientEvent_SetLink",
    	{
    	toPosition = "vec3"
    	}
    )
    NKRegisterEvent("ClientEvent_ResetLink",
    	{
    	}
    )
    
    
    -------------------------------------------------------------------------------
    function GourdFence:Constructor(args)
    	self.m_linked = false
    	self.m_linkedposition = nil
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:Interact( args )
    	if not self.m_linked then
    		return
    	end
    
    	self:RaiseClientEvent("ClientEvent_TeleportToLinked", 
    	{ 
    		playerToAffect = args.player.object
    	})
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:ClientEvent_SetLink(args)
    	self.m_linkedposition = args.toPosition
    	self.m_linked = true
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:ClientEvent_TeleportToLinked(args)
    	playerToAffect:NKSetPosition(self.m_linkedposition)
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:ClientEvent_ResetLink(args)
    	self.m_linked = false
    	self.m_linkedposition = nil
    end
    
    -------------------------------------------------------------------------------
    EntityFramework:RegisterGameObject(GourdFence)
    
    Gourd Wand - The one that doesn't save
    The txt file
    GameObjects
    {
    
    	Equipable
    	{
    
    		Gourd Wand
    		{
    			Transform
    			{
    			}
    			Script
    			{
    				file = "Scripts/Objects/GourdWand.lua"
    				class = "GourdWand"
    				arguments
    				{
    					encumbrance = 0.15
    				}
    			}
    			
    			StaticGraphics
    			{
    				model = "Models/PlaceableObjects/Harvestables/woodStickForked.obj"	
    				dontCastShadows = 1.0
    				Diffuse
    				{
    					0 = "Character/Tools/gourd_wand.tga"
    				}				
    			}
    			
    			RigidBody
    			{
    				activePhysics = 1
    				mass = 1
    				friction = 5
    			}
    			
    			Equipable
    			{
    				name = "Gourd Wand"
    				minScale = 1.0
    				maxScale = 1.0
    				icon = "0clubThorns_TLV"
    				category = "Weapon"
    				tier = 2
    				creakingSound = "ItemCreak"
    				breakSound = "ItemBreak"
    				impactFailSound = "WoodDig"
    				durability = 240
    				durabilityCreakingPoint = 8.0
    				attackSpeedModifier = 1.5
    				maxStackCount = 1
    				resource = 0
    				
    				Equipment Slots
    				{
    					Weapon
    				}
    			}		
    		}
    	}
    }
    
    The Lua file
    include("Scripts/Objects/Equipable.lua")
    
    -------------------------------------------------------------------------------
    GourdWand = Equipable.Subclass("GourdWand")
    
    -------------------------------------------------------------------------------
    --Mixin
    GourdWand.StaticMixin(Usable)
    
    -------------------------------------------------------------------------------
    function GourdWand:Constructor( args )
    	self.m_object1 = nil
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:PrimaryAction( args )
    	if (self.m_object1 == nil) then
    		return
    	end
    
    	if (NKGetName(args.object) == "Gourd Fence") then
    		args.object:RaiseClientEvent("ClientEvent_SetLinked", {toPosition = NKGetWorldPosition(self.m_object1)})
    		self.m_object1:RaiseClientEvent("ClientEvent_SetLinked", {toPosition = NKGetWorldPosition(args.object)})
    		self:ModifyStackSize(-1)
    	end
    end
    
    -------------------------------------------------------------------------------
    function GourdWand:SecondaryAction( args )
    	if NKGetName(args.object) == "Gourd Fence" then
    		self.m_object1 = args.object
    	end
    end
    
    -------------------------------------------------------------------------------
    EntityFramework:RegisterGameObject(GourdWand)
    
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla Posts: 283 Developer
    In the txt files if you define:
    resource = 0
    
    The object will not be pickup-able.

    Well the saving issues can be few things, you will need to create a new world that's for sure.
    Other than that make sure that in-world object don't have active physics before saving, as any object with active physics will currently not save.
    My Blog
    jc.png
      yt.png  t.png  
  • RawrRawr Posts: 508 Seed
    In the txt files if you define:
    resource = 0
    
    The object will not be pickup-able.

    *Hat tip*
    /hehe (I'll see what else I can change to have unintended consequences)
    Programmer, designer, artist.
  • RawrRawr Posts: 508 Seed
    Hey,
    Two things.

    First, I've been trying to access the x,y,z components of a vec3 that I'm passing through a ClientEvent_SetLink. NKPrint(args.toPosition) turns up with <userdata 1> ... how do I change that into the different components? I've been mucking around with unpack() and getmetatable() but nothings managed to get it just yet.
    edit: I should also note that my later attempts at NKPrint(args.toPosition.x) haven't worked.
    edit2: ok this is just silly.
    include&#40;"Scripts/Interactable.lua"&#41;
    include&#40;"Scripts/Objects/PlaceableObject.lua"&#41;
    
    -------------------------------------------------------------------------------
    GourdFence = PlaceableObject.Subclass&#40;"GourdFence"&#41;
    
    -------------------------------------------------------------------------------
    --Register Events
    NKRegisterEvent&#40;"ClientEvent_TeleportToLinked",
    	{
    	playerToAffect = "gameobject"
    	}
    &#41;
    
    NKRegisterEvent&#40;"ClientEvent_SetLink",
    	{
    	toObject = "gameobject",
    	toPosition = "vec3"
    	}
    &#41;
    NKRegisterEvent&#40;"ClientEvent_ResetLink",
    	{
    	}
    &#41;
    
    
    -------------------------------------------------------------------------------
    function GourdFence:Constructor&#40;args&#41;
    	self.linked = false
    	self.linkedposition = nil
    	self.linkedobject = nil
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:Interact&#40; args &#41;
    	if not self.linked then
    		return
    	end
    	self:RaiseClientEvent&#40;"ClientEvent_TeleportToLinked", {playerToAffect = args.player.object}&#41;
    end
    
    -------------------------------------------------------------------------------
    --making sure the link gets deleted on both ends when one of the objects despawns.
    function GourdFence:Despawn&#40;&#41;
    	if self.linkedobject then
    		self.linkedobject:ClientEvent_ResetLink&#40;&#41;
    	end
    	self:ClientEvent_ResetLink&#40;&#41;
    end
    -------------------------------------------------------------------------------
    function GourdFence:ClientEvent_SetLink&#40;args&#41;
    	self.linkedposition = vec3.new&#40;args.toPosition&#41;
    	self.linkedobject = args.toObject:NKGetInstance&#40;&#41;
    	self.linked = true
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:ClientEvent_TeleportToLinked&#40;args&#41;
    	local worldPlayer = args.playerToAffect:NKGetWorldPlayer&#40;&#41;
    	worldPlayer:NKTeleportToLocation&#40;self.linkedposition&#41;
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:ClientEvent_ResetLink&#40;&#41;
    	self.linked = false
    	self.linkedposition = nil
    	self.linkedobject = nil
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:Save&#40; outData &#41;
    	outData.link = self.linked
    	outData.linkposition = self.linkedposition
    end
    
    -------------------------------------------------------------------------------
    function GourdFence:Restore&#40; inData, version &#41;
    	self.linked = inData.link
    	self.linkedposition = inData.linkposition
    	--This needs to be done so that links properly get destoryed.
    	--local radObjects = NKGetGameObjectsInRadius&#40;inData.linkposition, 1.0, "GourdFence"&#41;
    
    end
    -------------------------------------------------------------------------------
    EntityFramework:RegisterGameObject&#40;GourdFence&#41;
    
    The inData.linkposition turns into the origin (0, 0, 0).
    local vecVar = vec3.new(1.0, 1.0, 1.0)
    NKPrint(NKToString(vecVar))
    ....Not even that worked for me.
    I need the low down on whats going on here.

    Secondly, I'm wanting to use the NKSpawnGameObject() with my own Commands Script but apparantly my test run of NKSpawnGameObject("Purple Gourd", 2) == error NKSpawnGameObject("a nile value")

    help?
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla Posts: 283 Developer
    Vec3 can be accessed like this
    pos:x()
    pos:y()
    pos:z()

    To print it use NKPrint(pos:NKToString())

    To print the metatable use NKPrint(EternusEngine.Debugging.Inspect(getmetatable(pos)) .. "

    ")

    BTW: NKGetGameObjectsInRadius should be used like this:
    local gameobjects = Eternus.GameObjectSystem:NKGetGameObjectsInRadius(position, radius, "all", false)
    

    To spawn items use:
    local item = Eternus.GameObjectSystem:NKCreateNetworkedGameObject(objectName, true, true)
    
    -- You need to make sure it is stackable if you want to use that function
    -- if item:NKGetInstance().ModifyStackSize then
    quantity = item:NKGetInstance():ModifyStackSize(quantity)
    
    -- Set Position
    item:NKSetPosition(location)
    -- Place in the world
    item:NKPlaceInWorld(true, false)
    
    -- If it has physics, set it to dynamic via NKActivate
    if item:NKGetPhysics() then
    	item:NKGetPhysics():NKActivate()
    end
    

    Also have a look at:
    function ChatCommandsLogic:ServerEvent_SpawnCommand(args)

    It has full implementation for stackable and non-stackable items, that function is called on when you use /spawn "Item Name" x
    My Blog
    jc.png
      yt.png  t.png  
  • RawrRawr Posts: 508 Seed
    Thank you.
    As you might've picked out, this frustrated me. I knew I had the right functions but couldn't put it together in the way LUA wanted ... sigh.
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla Posts: 283 Developer
    Rawr wrote:
    Thank you.
    As you might've picked out, this frustrated me. I knew I had the right functions but couldn't put it together in the way LUA wanted ... sigh.

    We have all been through it, glad I could help. The API and LUA takes a while to get used to, good thing it is consistent so once you get the hang of it you should be fine.
    My Blog
    jc.png
      yt.png  t.png  
Sign In or Register to comment.