Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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"},	
	}
}
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post 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?
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post 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)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post 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?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post 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.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Ask a simple question, get a simple answer

Post 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. :)
Post Reply