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
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Aha: problem.

A delayedCall command runs to the end, you can't pause it, right?

Well, my candle runs out of "wax" when it it lit. Means: when carried in a champions attack hand. If I start a delayedCall as soon as a champion holds the candle in hand it will vanish even the player removed it after 2 seconds. I think I have to use a timer anyway.

Create it on the fly and give it as its ID the ID of the candle item plus a suffix to make it different. This timer is running then only as long as a champion holds the candle. If not, it gets paused.

I see a few other problem coming but I will give it a try.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

I'd suggest adding a TimerComponent to the party on the fly instead of spawning a new object, so that you don't have the issue of the timer slowing down if the party leaves the map.
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
ratman
Posts: 159
Joined: Fri Jan 10, 2020 1:13 am

Re: Ask a simple question, get a simple answer

Post by ratman »

I assume the compass is hardcoded? Or has anyone made their own compass that functions the same?

edit: Also how does the

Code: Select all

LightComponent:setColor(color)
function work? I try this:

Code: Select all

light_component:setColor(50, 50, 25)
and is crashes the game saying it expects 'vec', but got 'number'.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

You need to pass vec(50, 50, 25) instead of just 50, 50, 25.

The compass is hardcoded, but it should be straightforward to re-implement: every frame, search the party's inventory for any compasses (the Head Hunter trait is a good example of searching party inventories) and use setGfxIndex() to set their icon according to the party's current facing. You could also look at script_entity_18 in the Twisted Passage level of Isle of Nex (here is a dungeon editor file that will load Isle of Nex) which handles the cursed compass.
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
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Okay, some more questions.

I have an object from which on I have to create a monster and give it an onDie connector back to the former object (to a script component in it).

My problem: Since there could be more than one instance of the object (and then the monster) I cannot give them fixed IDs. So how to adress the monster and then back the object?

What I have tried is:

Code: Select all

			onClick = function(self)
					local tenta = spawn("tentacles", self.go.level, self.go.x, self.go.y, self.go.facing, self.go.elevation)
					local scr = self.go.id
					tenta.monster:addConnector("onDie", "scr" , "setRight")
			end,
But that doesn't work. The target "scr" cannot be found. Also not scr (without quotes) or immediatly self.go.id or "self.go.id". So how to do this?

(The trick would also be needed for my candle item which is still not finished.)
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

THOM wrote: Sun Dec 06, 2020 10:22 am I have an object from which on I have to create a monster and give it an onDie connector back to the former object (to a script component in it).

My problem: Since there could be more than one instance of the object (and then the monster) I cannot give them fixed IDs. So how to adress the monster and then back the object?
You've made something like this?

Code: Select all

defineObject{
	name = "wall_button_new",
	components = {
		{
			class = "Model",
			model = "assets/models/env/wall_button.fbx",
		},
		{
			class = "Animation",
			animations = {
				press = "assets/animations/env/wall_button_press.fbx",
			}
		},
		{
			class = "Clickable",
			offset = vec(0,1.375,0),
			size = vec(0.25, 0.25, 0.25),
			--debugDraw = true,
		},
		{
			class = "Button",
			sound = "button",
			onActivate = function(self)
				-- Spawn a monster one tile west of the button
				local monster_entity = spawn("spore_mushroom", self.go.level, self.go.x - 1, self.go.y, self.go.facing, self.go.elevation)
				monster_entity.monster:addConnector("onDie", self.go.id, "scriptOnDie")
			end,
		},
		{
			class = "Script",
		},
		{
			class = "ScriptController",
			name = "controller",
		},
	},
	placement = "wall",
	editorIcon = 12,
}
And in the dungeon editor, you've set the script to something like:

Code: Select all

function scriptOnDie(monster)
	print("scriptOnDie", monster.go.name, monster.go.id)
end
All I can say is "Works for me."
When I press the button and then kill the monster, LoG2 prints "scriptOnDie spore_mushroom 653" in the console.
User avatar
ratman
Posts: 159
Joined: Fri Jan 10, 2020 1:13 am

Re: Ask a simple question, get a simple answer

Post by ratman »

Is there some sort of delayed hudPrint function so all the lines don't show up at once? or do I just have to use timers?
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

ratman wrote: Sun Dec 06, 2020 5:40 pm Is there some sort of delayed hudPrint function so all the lines don't show up at once? or do I just have to use timers?
You can use:
delayedCall(receiver, delay, msg)
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

THOM wrote: Sun Dec 06, 2020 10:22 am Okay, some more questions.

I have an object from which on I have to create a monster and give it an onDie connector back to the former object (to a script component in it).

My problem: Since there could be more than one instance of the object (and then the monster) I cannot give them fixed IDs. So how to adress the monster and then back the object?

What I have tried is:

Code: Select all

			onClick = function(self)
					local tenta = spawn("tentacles", self.go.level, self.go.x, self.go.y, self.go.facing, self.go.elevation)
					local scr = self.go.id
					tenta.monster:addConnector("onDie", "scr" , "setRight")
			end,
But that doesn't work. The target "scr" cannot be found. Also not scr (without quotes) or immediatly self.go.id or "self.go.id". So how to do this?

(The trick would also be needed for my candle item which is still not finished.)
self.go.id should work. Did you forget to put a ScriptControllerComponent named "controller" on the object?
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
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Thanks, guys.
Got it.

The problem was not the adressing of the function but the function itself.
1. it had a misspelled command createComponent in it (the component to be created must be written in upper case e.g. "Socket")
2. there was also a problem in it with the self.go.id term - but I could solve this

Now it works.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Post Reply