Page 180 of 396

Re: Ask a simple question, get a simple answer

Posted: Wed Jan 11, 2017 8:56 am
by Isaac
What stops delayedCall and timer connections (among others?) from accessing functions defined in [assigned to] an object's script component?

For example, I find that both delayedCall and timers will print errors in the console for an invalid target, when the script functions were defined in an onInit hook.
(Yet those functions can be called directly from other hooks, and even from the defined script itself.)

Code: Select all

 --place and equip this object
defineObject{
	name = "scripted_figure_skeleton",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/figure_skeleton.fbx",
		},
		{
			class = "Item",
			uiName = "Skeleton Figurine",
			gfxIndex = 363,
			description = "This figurine is crafted out of a single piece of pale bone.",
			weight = 0.2,
			onEquipItem = function(self)
						self.go.script:test()
						delayedCall(self.go.id, 1, "test")
					end
		},
		{
			class = "ScriptController", --or Null
			onInit = function(self) self.go.script:setSource(
					[[
						function test2(caller) 
							if caller then
								print("Test2 function was called via "..caller:getName()) end
							end		

						function test(caller)
							if caller then
								print("Test function was called via "..caller:getName())
								self.go.script:test2()
							end
						end
					]]) 
				end,
		},
		{class="Script"},	
	}
}

Re: Ask a simple question, get a simple answer

Posted: Wed Jan 11, 2017 10:03 am
by zimberzimber
Since what you posted is an item that has to be equipped, then maybe this has to do with it not being on the map and the script not finding it?

Re: Ask a simple question, get a simple answer

Posted: Wed Jan 11, 2017 10:23 am
by Isaac
zimberzimber wrote:Since what you posted is an item that has to be equipped, then maybe this has to do with it not being on the map and the script not finding it?
Actually it is just an example I made to demonstrate the problem.

*But... that doesn't mean that's not the reason. ;) It is something to look into; it's good insight, thanks.

Update: This certainly has something to do with it. I changed the code to direct the delayedCall at another instance of the object; this one was on the map. The error didn't print this time; but the function still didn't run.
removing the object from the map (into inventory), and trying again, produced the error again.

Re: Ask a simple question, get a simple answer

Posted: Thu Jan 12, 2017 2:24 am
by minmay
delayedCall and other connectors don't call ScriptComponent functions directly. They must go through a ScriptControllerComponent named 'controller' first. If a ScriptControllerComponent is not named 'controller' then it's pretty much useless. You wanted:

Code: Select all

      {
         class = "ScriptController",
         name = "controller",
         onInit = function(self) self.go.script:setSource(
               [[
                  function test2(caller)
                     if caller then
                        print("Test2 function was called via "..caller:getName()) end
                     end      

                  function test(caller)
                     if caller then
                        print("Test function was called via "..caller:getName())
                        self.go.script:test2()
                     end
                  end
               ]])
            end,
      },
(Connectors also don't really work if either the sender or receiver is not on any map, yes)

Re: Ask a simple question, get a simple answer

Posted: Thu Jan 12, 2017 5:37 am
by Isaac
minmay wrote:...You wanted:

Code: Select all

  
         name = "controller",
Thank you, indeed it is.
I recalled that a ScriptController was needed, but I'd assumed that it would [should] take the name 'scriptcontroller', rather than 'controller', as with Controller components.
(Connectors also don't really work if either the sender or receiver is not on any map, yes)
The fix was to spawn a support script (for all like items), if one did not exist.

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 14, 2017 5:09 pm
by AndakRainor
I just started working on a custom camera component (with fov = 100), and I get randomly wrong aspect ratio in the editor preview. Does anyone get this? Do you know what is going on? Is aspect ratio bugged in the game too?

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 14, 2017 5:15 pm
by Isaac
I haven't really delved into that yet, but I do know that when writing GUI menu elements, the preview [being dynamically whatever arbitrary aspect the window is sized to] often displays the offsets incorrectly.

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 14, 2017 5:33 pm
by zimberzimber
AndakRainor wrote:I just started working on a custom camera component (with fov = 100), and I get randomly wrong aspect ratio in the editor preview. Does anyone get this? Do you know what is going on? Is aspect ratio bugged in the game too?
The camera adjusts itself to the in-game window. Enlarging the window will not change anything, so the ratio will still be [the FOV you set it to], but only for the initial screen size of the in-game window.
You can scale the window to the max and then run it.

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 21, 2017 12:37 pm
by Isaac
Is the meleeAttackComponent:onPostAttack() hook DOA? I cannot get it to trigger.

Edit: Nevermind... It seems to only trigger if the champion misses.

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 21, 2017 1:40 pm
by Grimfan
Okay, back to modding (and relearning the basics of lua) after a long absence and I have a question:

Does anyone know of any good methods for getting creatures to open doors without using floortriggers, which are not 100% full proof, and with the assumption that these creatures will be killed by the player at some point? I know there is probably more than one solution to this issue but after scouring previous posts I'm no closer to the answer.

Thanks in advance for any help in this regard. :)