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!
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Ask a simple question, get a simple answer

Post by Azel »

I noticed that when your timer Activates, it calls a method, "moveThat"

Cant you have a global counter that keep tracks of when the instructions inside of moveThat actually execute? Granted, the Timer will always run but the instructions will only execute based on the value of a Party Counter.

Something like:

Code: Select all

function moveThat()

	local partyCounter = findEntity("PartyCounter");
	
	if partyCounter then
		if partyCounter.counter:getValue() > 0 then
			-- Do THOM's magic
		end
	end

end
Sorry, just thinking of an alternate way to accomplish the same thing :D
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:Really a simple question but it drives me mad:

I want to add a timer component to the party object which starts NOT at the beginning of the game. Cannot find a command to disable it. I am pretty sure it is very obvious but I am unable to figure it out.

Any help, please?
To start a component disabled, include

Code: Select all

enabled = false,
in its definition.
You also could have discovered this by looking at the scripting reference or the asset pack.
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.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Ask a simple question, get a simple answer

Post by Azel »

minmay wrote:You also could have discovered this by looking at the scripting reference or the asset pack.

The name of this thread is "ask a simple question, get a simple answer"

You seem to think the name is, "dont ask a question, go look at the scripting reference or the asset pack"

Also, nowhere in the Scripting Reference does it answer THOM's question: http://www.grimrock.net/modding/scripti ... rComponent

Also, the LOG2 Asset Defs.LUA file does not show the "enabled=false" property setting, it simply has this:

Code: Select all

defineObject{
	editorIcon = 64,
	tags = {
		"scripting"
	},
	name = "timer",
	components = {
		{
			name = "timer",
			class = "Timer"
		},
		{
			onStart = function() print('Cannot Scrape Functions'); end,
			onPause = function() print('Cannot Scrape Functions'); end,
			class = "Controller",
			name = "controller",
			onStop = function() print('Cannot Scrape Functions'); end
		}
	},
	placement = "floor"
}
In fact, "enabled=false" is nowhere in that Asset file.

Of course, there are well over 100 Script Files also provided in the Asset Pack that could be reviewed to find this answer, but luckily there is a community to discuss things with. Lastly, just like you like to repeatedly point out that there is a scripting reference and asset pack, let me point out that there is a "Reply" button that you do not have to Click every time someone asks a question. Food for thought :mrgreen:
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Azel wrote:Also, nowhere in the Scripting Reference does it answer THOM's question: http://www.grimrock.net/modding/scripti ... rComponent
Yes it does. Maybe you should read it yourself.
The components field should contain a list of components to be added or replaced in the base object class. Each component has a class and a name. The name of a component is by default its class in lower case. Each component have the following fields:

class: the class name of the component without the “Component” part. E.g. “Model”.
name: (optional) the name of the component. Convention is to use lower case names.
enabled: (optional) the initial enabled state of the component (default is true).
xyz: (optional) sets the xyz property of the component by calling setXyz() method of the component. Any setter that receives a single parameters can be called using this mechanism.
onXyz: (optional) adds the xyz hook to the component.

...

Component

Base-class for all Components. A Component always belongs to one and only one GameObject. Components can be enabled and disabled. A disabled component usually acts as it would not exist in the game.
Component:addConnector(event, target, action)
Component:disable()
Component:enable()
Component:getConnector(i)
Component:getConnectorCount()
Component:getOffset()
Component:isEnabled()
Component:removeConnector(event, target, action)
Component:setOffset(offset)
Component:setRotationAngles(x, y, z)
Component.onInit(self)
I don't recall telling him not to post. I did imply that it would be a good idea to look at the scripting reference first, simply because that's much faster than waiting for someone to reply.
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.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Ask a simple question, get a simple answer

Post by Azel »

minmay wrote:Yes it does. Maybe you should read it yourself.
If it was stated on the scripting reference then you could quote the exact location. It doesn't, so you can't. The "one shot" vs "running mode" is loose language, as is most of the scripting reference; which does not denote exact required syntax - which is what THOM was asking for.
minmay wrote:I did imply that it would be a good idea to look at the scripting reference first, simply because that's much faster than waiting for someone to reply.
Speed isn't always the goal; collaboration yields more benefits. I'm sure anyone who frequents this forum has read one of the hundreds of times you've named dropped the scripting reference and asset pack. Your name dropping is usually wrong (like in this case) and clearly only serves as another of your attempts to act "elite" - which I still believe is highly misplaced. Memorizing someone elses files is cool n all, but why you think that puts you above others is pretty silly.

If someone wishes to post a question instead of reading reference/script files, then it isn't your place to chastise their preference of community collaboration over speed.
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 »

minmay wrote:

Code: Select all

enabled = false,
I knewed it was something very simple...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Ask a simple question, get a simple answer

Post by cromcrom »

A simple way to destroy this timer once it is activated please ?

Code: Select all

		local bandagetimer = spawn("timer",1,1,1,1,1,"bandage_applied")
		bandagetimer.timer:setTimerInterval(3)
		bandagetimer.timer:setDisableSelf(true)	
A trip of a thousand leagues starts with a step.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

cromcrom wrote:A simple way to destroy this timer once it is activated please ?

Code: Select all

	local bandagetimer = spawn("timer",1,1,1,1,1,"bandage_applied")
		bandagetimer.timer:setTimerInterval(3)
		bandagetimer.timer:setDisableSelf(true)	
Adding a function to your script that destroys the caller can work; just connect the timer to it.

Code: Select all

function destroyCaller(caller)
	if caller and caller.go and caller.go.timer then
		caller.go:destroyDelayed()
	end
	print(caller.go.id, 'destroyed')
end
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Ask a simple question, get a simple answer

Post by cromcrom »

Thanks a lot, it makes a lot of sense. Cheers.
A trip of a thousand leagues starts with a step.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Ask a simple question, get a simple answer

Post by cromcrom »

I am still banging my head on this:
so, in a function, I create this timer.

Code: Select all

		local bandagetimer = spawn("timer",1,1,1,1,1,"bandage_applied")
		bandagetimer.timer:setTimerInterval(3)
		--bandagetimer.timer:setDisableSelf(true)
		--bandagetimer.timer:start()		
		bandagetimer.timer:addConnector("onActivate", "destroy_timer", "destroyCaller","bandage_applied" )
then, when it activates, it calls this function:

Code: Select all

function destroyCaller(caller)
  if findEntity(caller) then
    findEntity(caller):destroyDelayed()
   end
   print(findEntity(caller), 'destroyed')
end
However, I have a "could not look up class name " error. Any help, please? I know I could go the rough way, it does work, but I would like to have a broader destroying function, where I can pass the id as an argument.
A trip of a thousand leagues starts with a step.
Post Reply