Page 213 of 400

Re: Ask a simple question, get a simple answer

Posted: Sat Sep 16, 2017 10:40 pm
by Xardas
Thank you guys, i knew that the castle walls are higher than the regular ones, but i dind´t knew about the module height.

Re: Ask a simple question, get a simple answer

Posted: Thu Sep 21, 2017 9:00 pm
by Xardas
hey guys
i´m currently using an external script as an onThink hook for a custom brain. Is it possible to load a new file to the script, so the trickster "uses a different brain"?. I tried it with loadFile and setSource, but both don´t work properly
Monster Definition for the trickster with custom brain:

Code: Select all

defineObject{ 
name = "trickster_test", 
baseObject = "trickster", 
components = { 
{ 
class = 'Brain', 
onThink = function(self) 
trickster.script.onThink(self) 
end 
} 
} 
}
file i´d like to load to the script for new brain behavior:

Code: Select all

function onThink(self)

local brainaction = braincounter.counter:getValue()
local brain = self.go.brain

if brainaction==1 then
brain:strafeLeft()
delayedCall("trickster", 1, "increment", self.go.id)

elseif brainaction==2 then 
self.go.animation:play("scold")
brain:disable()
delayedCall("trickster", 2.66, "increment", self.go.id)

elseif brainaction==3 then
self:goTo("lever_1") 
if self:goTo("lever_1") then
brain:operate("lever_1")
increment()
end

elseif brainaction==4 then
brain:seek(13,18)
if self.go.x == 13 and self.go.y == 18 then
increment()
end
elseif brainaction==5 then
self:performAction("escape") 
end
end

function increment(self)
braincounter.counter:increment() 
trickster_test_1.brain:enable()
end

Re: Ask a simple question, get a simple answer

Posted: Thu Sep 21, 2017 9:51 pm
by Isaac
You tell the brain to do nothing, by returning true from your onThink hook; otherwise it uses the built in logic.

Re: Ask a simple question, get a simple answer

Posted: Thu Sep 21, 2017 11:19 pm
by Xardas
With the built in logic you mean the normal brainscript right? I just tried returning false and then he does nothing.

Re: Ask a simple question, get a simple answer

Posted: Fri Sep 22, 2017 12:42 am
by Isaac
Xardas wrote:With the built in logic you mean the normal brainscript right? I just tried returning false and then he does nothing.
https://github.com/JKos/log2doc/wiki/Co ... -component
When implementing onThinkon a built-in brain, it's possible to override the built-in behaviour in some specific cases while keeping the default implementation for the rest:

The onThink hook should return true when an action is performed (wait() and performXXX() methods already return true, so it's possible to write, for example return self:wait())
If the onThink hook does not return true, the built-in logic kicks in and control for the next action is passed to the built-in brain.

Here is a test project:
Image
https://www.dropbox.com/s/k1r75li191fv4 ... t.zip?dl=1

The script for the above example:

Code: Select all

questEnabled = true

function trapdoor(trigger)

	if trigger then 
		delayedCall(self.go.id, 2, "trapdoor")
	end
	dungeon_pit_trapdoor_1.pit:toggle()
end	

--Trickster

trickster_1.brain:addConnector('onThink', self.go.id, 'onThink')

function onThink(monster)
	local lock = findEntity("lock_gold_1")
		if  questEnabled == true then
		if  monster.go.brain:here(lock.id) then
			monster.go.brain:operate(lock.id) 
			lock.lock:enable()
		 else monster.go.brain:goTo(lock.id)
		end
	end
end

function setQuestEnabled(bool)
	if type(bool) == 'boolean' then questEnabled = bool end
end

function toggleQuestEnabled(lever) 
	 self.setQuestEnabled(lever.go.lever:isActivated())
end
Note that this script doesn't explicitly return a value from the onThink hook for this case.

Re: Ask a simple question, get a simple answer

Posted: Fri Sep 22, 2017 3:04 pm
by Xardas
That script was very helpful, thank you. I think i got it now.

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 10, 2017 9:45 pm
by Isaac
Did they update LoG2 to support a larger file-size for mods, on Steam? (I use the GoG version)

As I recall, the effective size limit for LoG1 Steam mods was stated to be 100mb, (but in practice turned out to be 98mb).
It was a nightmare to get ORRR2 (for LoG1) under 98mb.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 10, 2017 2:26 am
by Xardas
Hey guys it´s me again
Does anyone know how to generate random numbers?. math.random() just doesn´t do its Job.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 10, 2017 3:44 am
by Isaac
Xardas wrote:Hey guys it´s me again
Does anyone know how to generate random numbers?. math.random() just doesn´t do its Job.
The math.random function does generate it (pseudo-random numbers), but if you use it too early during load, your results could be poor; or perhaps even repeating.

You can set the seed of math.random with math.randomseed(your_number_value), to change its number queue.

There is also the mersenne twister.
https://github.com/JKos/log2doc/wiki/Ob ... nnetwister
http://www.grimrock.net/modding/scripti ... nneTwister

Seeding math.randomseed with the current system time would result in a different stream of numbers from math.random for every second of the day.

math.randomseed(Time.currentTime()) or math.randomseed(Time.systemTime())

math.random()
math.random()
math.random()...

If you are seeding the function in a hook with GUI context, you could salt the seed with the mouse coordinates as well.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 10, 2017 8:26 am
by minmay
Time.systemTime() returns the number of seconds that the game has been running, with millisecond precision. It tells you nothing about real-world time (and neither does anything else available in the scripting interface). It is probably still the best option for seeding a PRNG, though.

Grimrock calls math.randomseed() when loading a dungeon and when initializing maps (so that tilesets don't provide different results across loads), and whenever the player opens the automap. So if you're using math.random() in your init files it'll always give the same results across loads, and if you're using it during a game you should be aware it could be re-seeded at pretty much any time.