Wish there was more info on the Brain component

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!
Post Reply
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Wish there was more info on the Brain component

Post by MrChoke »

My next challenge is to see if I can get some custom AI going. I know this is going be tough. For starters, there are a few BrainComponent functions that I wish I understood more.
Take these for example:

BrainComponent:goTo(string)
BrainComponent:here(string)

They want a string input. But what is the string? And what do they do? I am thinking goto means go to a square? But wouldn't it need at least two parameters?

BrainComponent:operate(string)
BrainComponent:seek(number)

Two more functions. No idea what the input is or what they do. I wish I did. I have so many ideas......
minmay
Posts: 2770
Joined: Mon Sep 23, 2013 2:24 am

Re: Wish there was more info on the Brain component

Post by minmay »

I'm sure there will be more info when the scripting reference is finished.
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
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Wish there was more info on the Brain component

Post by Prozail »

goTo atleast takes an item-id as input... so you can do

function onThink()
if something:goTo("lever_1") then
print("I AM HERE!")
end
end
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Wish there was more info on the Brain component

Post by JKos »

Other examples can be found here:
viewtopic.php?f=22&t=7918
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Wish there was more info on the Brain component

Post by MrChoke »

I did figure out a few on my own too after the post.

BrainComponent:goTo(string)
Input is the id of an object to move to. It will only work if the monster is on the same level as object

BrainComponent:here(string)
Input is an object ID again and reports true if the monster is in the same square as the object

I cannot seem to get a few others to work:

BrainComponent:openLockWith(string, string)
I assume these are IDs again. Is it lock_Id then key_id? I have tried every combination I can think of.

BrainComponent:operate(string)
This is for levers and buttons? I cannot get him to operate a button. I didn't try a lever yet, I will do that


JKos, I read the post you gave. Perhaps I couldn't get it to work because of the monster I was using. I used a skeleton_trooper. I will see about using a Herder since that was in the post.

This next one I didn't try yet and I really don't know what the input should be:
BrainComponent:seek(number)

Seek what? With what number?
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Wish there was more info on the Brain component

Post by MrChoke »

@JKos,
I looked at all the examples you gave in the other post. I have a question about this code:

Code: Select all

  onThink = function(self) 
         self:turnLeft()
      end,
      onThinkSpecial = function(self,arg1,arg2,arg3) 
         self:turnRight()
      end,     
I see onThinkSpecial() defined for a Trickster brain. Believe or not I didn't finish the game yet so I am not sure who this guy is!! So is onThinkSpeical() called each time onThink() is? Is there any difference?

Thanks
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Wish there was more info on the Brain component

Post by JKos »

That example was before when the official scripting reference was released, I dug those hooks from .dat file and thought that they were both available for normal BrainComponent. I haven't played with trickster brain yet, so I don't know when onThinkSpecial is called. Maybe someone else does?
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Wish there was more info on the Brain component

Post by MrChoke »

JKos wrote:That example was before when the official scripting reference was released, I dug those hooks from .dat file and thought that they were both available for normal BrainComponent. I haven't played with trickster brain yet, so I don't know when onThinkSpecial is called. Maybe someone else does?
Ok thanks. I will keep trying to figure it out.

Do you know anything about seek(), openWithLock() or operate()? I couldn't get operate() or openWithLock() to work but maybe I need to use another monster.
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Wish there was more info on the Brain component

Post by Aisuu »

Sorry to jumping into your topic. But I have difficulty with brains too.
I need to script monster to patroll. For example going in circle, or from left to right guarding something. Then, as soon as monster see party, he go after them and forget patrolling :)
I also need to create neutral monster. Completely ignoring party, but become aggressive after party attack it.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Wish there was more info on the Brain component

Post by MrChoke »

Aisuu wrote:Sorry to jumping into your topic. But I have difficulty with brains too.
I need to script monster to patroll. For example going in circle, or from left to right guarding something. Then, as soon as monster see party, he go after them and forget patrolling :)
I also need to create neutral monster. Completely ignoring party, but become aggressive after party attack it.
Sounds like you want it to do some complicated stuff. All I can say is the way it works is you have to "override" a monster's default behavior in the onThink() hook and you need to keep having it override on every thought trigger. OnThink() is called multiple times before an action is made. It is called a ton. As soon as you stop telling the monster what to do in onThink() he will go back to his default behavior, whatever that may be (must depend on the specific BrainComponent)

I have found out the hard way that some Brain commands simply will not work for all but certain monsters. The trickster is by far the most advanced. But I believe all monsters will respond to turn commands, guard, move, flee, move toward party, etc... They also respond to seek() which tells him to go to a certain square or goTo() which tells him to go to an object as long as it is on the same level.
Post Reply

Return to “Mod Creation”