Page 9 of 16
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Tue Nov 27, 2012 10:39 pm
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.
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Tue Nov 27, 2012 11:31 pm
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.
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Wed Nov 28, 2012 12:16 am
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
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Wed Nov 28, 2012 9:14 pm
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.
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Wed Nov 28, 2012 10:36 pm
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.
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Thu Nov 29, 2012 7:19 pm
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"
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Thu Nov 29, 2012 9:09 pm
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.
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Fri Nov 30, 2012 8:31 pm
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.
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Sat Dec 01, 2012 1:52 pm
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
Re: LoG Framework (new: AD&D style spell book and 14 spells)
Posted: Sat Dec 08, 2012 11:34 pm
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.