LoG Framework (dynamic hooks etc.)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
StaticZ
Posts: 10
Joined: Thu Nov 22, 2012 10:46 pm
Location: Russia

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by StaticZ »

JKos wrote:I have many years of php and javascript experience though, so if you are familiar with those then maybe my scripts could be easy to understand for you. I would't say that it's the "best" because there probably is some really stupid solutions.
Sure, I also is expirience in C# and C/C++ and didn't know anything about lua scripting... But with help of your code it take about hour to understand main things which are nessesary for scripting, I even don't read any tutorials, except official LoG scripting reference. Just for now your code is easy to read and I don't think that it need optimization... Much more better to add more modules and abilities, thow as for me some functions has many not often using arguments )))

One more bug - in turn base mode turn is over if you try to go throw enemy or wall.
Game isn't a dream, it is the reality, reality which is coming while we dream...
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Ok, I uploaded a new version.
* timers - script entity (loaded automatically)
* fw_magic script entity (general magic related stuff)
* fw_fx (effects related stuff)
* add_spells (AD&D spells and the spell book, just load it with fw_loadModule('add_spells') and the magic system changes to AD&D style
- Fixed: talk script entity works on all levels now, (didn't need to use extended timer for this.)
- Fixed: Framework can be spawned to any level. Installation documentation changed so that it's spawned to party level. spawn("LoGFramework", party.level,1,1,0,'fwInit')

Sorry no documentation for new scripts yet, they are WIP, so bug reports/feedback is welcome.
- 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
User avatar
StaticZ
Posts: 10
Joined: Thu Nov 22, 2012 10:46 pm
Location: Russia

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by StaticZ »

Greate, already testing... you forget to write about timers:setLevels() in instal manual.

One more suggest - make talk more safty:

Code: Select all

function printNextFromQueue()
	talk_timer:deactivate()
	if talk.queue[1].callback then
		if talk.queue[1].callback(unpack(talk.queue[1].args)) and (talk.queue[1]) then
			hudPrint(talk.queue[1].text)
		end
	elseif (talk.queue[1]) then
		hudPrint(talk.queue[1].text)
	end 
	
	if (talk.queue[1]) then
		table.remove(talk.queue,1)
	end
	if (talk.queue[1]) then
		talk.recreateTimer()
		talk_timer:setTimerInterval(talk.queue[1].interval)
		talk_timer:activate()
	end
end
the problem is that if we clear queue at some moment (for example in calback) we can get crushing.

Also as for me its better to do:

function championSays(interval,champNumber,text,callback,callbackargs)
sameAsLastOne = (champNumber == 0) -- or that is beetter for me - (sameAsLastOne = (type(champNumber) == boolean))
....
end

it's much easy to read code when interval,champNumber, are BEFOR text
Game isn't a dream, it is the reality, reality which is coming while we dream...
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Thanks again for good feedback. I modified it like this

Code: Select all

function printNextFromQueue()
   talk_timer:deactivate()
   if not talk.queue[1] then return end
   if talk.queue[1].callback then
      local args = talk.queue[1].args or {}
      if talk.queue[1].callback(unpack(args)) and (talk.queue[1]) then
         hudPrint(talk.queue[1].text)
      end
   else
      hudPrint(talk.queue[1].text)
   end 
   
   table.remove(talk.queue,1)

   if (talk.queue[1]) then
      talk.recreateTimer()
      talk_timer:setTimerInterval(talk.queue[1].interval)
      talk_timer:activate()
   end
end
(callback arguments are optional now)

and added a new function

Code: Select all

function say(def)
	talk.championSays(def.text,def.interval,def.champion,def.sameAsLastOne,def.callback,def.args)
end
Usage example

Code: Select all

	talk.say{
		text='Hello',
		interval=1,
		champion=2,
		callback=function(condition) return condition end,
		args={false}
	}
This is the one of the nicest features in lua IMO. You can pass a table as the only argument like that.
Now it's pretty readable and you can choose the order of the arguments.

Only the text argument is obligatory. If you don't pass champion then it will be randomized.

Haven't updated the zip yet but you can copy paste these to your talk.lua.

A tip for debugging: I always copy paste the script to dungeon from module-lua file when I develop new features and comment out the fw_loadModule-call from init.lua. For example:
make a script entity named talk and copy paste the talk script there. Comment out
-- fw_loadModule('talk')

then add talk:activate() call to logfw_init.main-function. This way I get error messages in editor if something goes wrong.
- 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
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

I made debugging/developing easier, you can now just copy paste the script from a module to script entity with same name as the .lua file. That's it. Framework will print a message: 'module "'..moduleName..'" found from dungeon, script from lua file was not loaded' when you press play button.

Zip updated.
- 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
User avatar
StaticZ
Posts: 10
Joined: Thu Nov 22, 2012 10:46 pm
Location: Russia

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by StaticZ »

By the way, what about food eating bug? As i read somewhere on forum it was a bug of framework, can it be fixed? Maybe just overide eating code - it seems not difficult to make "eate hook"
Game isn't a dream, it is the reality, reality which is coming while we dream...
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Oh, there was still a bug, I thought that the food worked after I fixed the previous bug, which was that food could not be consumed at all, but now it doesn't effect to food bar. It seems to be so that the behavior of food is hard coded, so I disabled dynamic hooks for food for now. Now it works, but you can't use dynamic hooks for food items.

Zip updated, but you can update the framework/modules/fw.lua only.
- 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
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by Diarmuid »

Hi JKos,

when I install the framework, it seems to break magus' SDP module. (viewtopic.php?f=14&t=3201)

On those lines:

Code: Select all

   while party:getChampion(champID):getLevel() <= champLevel-1 do
      party:getChampion(champID):levelUp()
   end
I get an "attempt to index global 'fw' (a nil value)" error.

Do you know why this happens? Thanks!

EDIT: Ok, found out, I had to call his routine with a timer 1s after init, as the framework is loaded 0.5s after init.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

Yeah, it doesn't work because champion:levelUp() call calls the party:onLevelUp hook. But you don't need a timer for that, just call it from logfw_init.main function.

like this:

logfw_init

Code: Select all

spawn("LoGFramework", party.level,1,1,0,'fwInit')
fwInit:open()

function main()
	timers:setLevels(5)
	fwInit:close() 
       initParty()
}

function initParty()
...
   while party:getChampion(champID):getLevel() <= champLevel-1 do
      party:getChampion(champID):levelUp()
   end
...
end

- 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
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: LoG Framework (new: AD&D style spell book and 14 spells)

Post by JKos »

New version

V0.9 (2012-12-08)
Bug fix: occasional bad object error on framework load. (script entities were loaded in random order, now they are loaded in module loading order)
Bug fix: overriding a hook with fw.setHook didn't work correctly. (hook was called twice after override)
New feature: added onDeactivate-hook support to timers
Improvement: timers now use shared functions which saves resources.
Improvement: constant timers now use 0.1 seconds interval, which makes them more accurate on dungeon level changes.
Magic system code refactoring: moved a bunch of functions from add_spells to fw_magic spells, added default_spells module. (Magic system documentation is coming soon)
Documentation of help, fw and timers modules improved.
- 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
Post Reply