LoG Framework (dynamic hooks etc.)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
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 added a working flame arrow example to here: https://sites.google.com/site/jkosgrimr ... l-fw_magic

Lot's of things are still missing but I hope you will get the idea. Any 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
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,

Is there a way to delay the return of a function?

I'm trying to code a level, x, y, facing = getTeleportTarget(id) function which would return the target of a teleporter (unless I've missed this already somewhere?)

I thought of spawning a probe item on the teleporter then checking it's location. Problem is I need a delay so that it gets teleported, so I cannot just spawn and destroy it right away.

If I wrap the test code in one of your timers callbacks however, how can I return a value to the main function? Simplified example:

Code: Select all

function getTeleportTarget(id)
   -- spawn item on teleporter here
   
   timer:addCallcack in 0.05s(
      function(
          -- test for location here
      end
   )

   -- return value based on test inside call back
end
The above won't work because we'll get to the return code 0.05s before the callBack is called. But if I return from within the call back, it will return to the callCallbacks, right?

Thanks in advance for the help...
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 can see your problem, but unfortunately there is no way to delay the function return or pause the code. So you have to use callback for handling the return value.

Code: Select all



function getTeleportTarget(id,returnCallback)
   -- spawn item on teleporter here
   
   timer:setTimerInterval(0.05)
   timer.returnCallback = returnCallback

   timer:addCallback(
      function(self)
          -- test for location here
          self.returnCallback(level,x,y,facing)
      end
   )

   -- return value based on test inside call back
end

handleReturnValue = function(level,x,y,facing)
   -- target values are returned to this function
    -- so you can do your stuff here
end

getTeleportTarget('teleporter_1',handleReturnValue)

Not sure if this is a solution to your problem.

Edit: fixed the code
- 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 »

Hmm... I did not know you could pass functions as arguments, interesting.

In your code however, why would you pass the function as an argument and define it as an entry in the timer properties table? Isn't it equivalent to:

Code: Select all

function getTeleportTarget(id)
   -- spawn item on teleporter here
   
   timer:setTimerInterval(0.05)

   timer:addCallback(
      function(self)
          -- test for location here
          handleReturnValue(level,x,y,facing)
      end
   )

   -- return value based on test inside call back
end

handleReturnValue = function(level,x,y,facing)
   -- target values are returned to this function
    -- so you can do your stuff here
end

getTeleportTarget('teleporter_1')
The above being the whole structure of functions calling themselves in loops within callbacks I use in my spells script. What am I missing?

Anyway, after thinking a bit more about it, I dropped the idea of automatically get a teleporter id - there's no reliable way to do it. It was for a particular spinner object, but people will have to provide the target manually.
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 »

Yes it basically the same, but my solution is more generally usable: You can write multiple returnValueHandlers.

But anyway I uploaded a new version:

V0.9.5 (2012-12-12)
- GrimQ included as a core module (Thanks to Xanathar who is the author of this really great and useful library)
GrimQ is loaded automatically, but you can also copy paste the GrimQ code to the dungeon and the framework will not load the included version. For example if you want to use a newer version than the included one. See: https://sites.google.com/site/jkosgrimr ... dule-grimq
- Documentation improved. IMO it's now much clearer and easier to read. (Found a table of contents widget from Google sites, and I have to say that Google sites rocks, really nice and FREE service)
- 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,

I have a question. In your guidelines, you mention that in init.lua, the framework should be imported after standard_assets.lua. However, I've noticed that if I want the hooks shortcut "monsters" to apply to custom monsters as well, I had to import framework.lua after all custom assets and add custom monsters to lists.monster in fw.lua (so that they get cloned properly).

Is there another way to do this that I've missed?
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 have a new version ready to be uploaded which adds automatic support for custom monsters and other assets, so you don't anymore have to add them to monsters lists (thanks to Xanathars grimq). I will upload it soon, but I think i'm testing a new LoG version a while. So much to do and so little time...
- 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
LordYig
Posts: 175
Joined: Wed Jul 04, 2012 5:45 pm

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

Post by LordYig »

Nice to see there is yet some more improvement to the framework !

I don't know if I should post this here but since it regards the casting and fighting system...

I had some weird ideas regarding spells yesterday.
Do you think it would be hard to add incantation sound/chant to every spells ?
Spell casting is kinda like shooting an arrow right now (the runes apart) and that's weird.

You could think of a similar system for the other character fighting method also.
Warrior shoutin/screaming while swinging their weapons, rogues sighing while throwing weapons or using projectiles, etc.

If this can be done and if this is not a performance killer, that could add some nice atmosphere to the fighting system don't you think ?
This may be a bad idea, I d'ont really know...
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

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

Post by Grimwold »

That shouldn't be too difficult to implement using party hooks... e.g.

Code: Select all

onCastSpell(champ,spell)
  if spell == "fireball" then
    playSound("incantation_1")
  elseif spell == "fireburst"
    playSound("incantation_2")
  end
  return true
end
You'd need a sound sample for each incantation and a definition in sounds.lua for each.

same could be done for onAttack.. either based on what weapon is used, or which champion is attacking.

Who can forget the classic DM warcry... yeeearrrgghh!
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 with better custom assets support. Not perfect yet, but at least you don't have to modify the fw.lua anymore :)

https://sites.google.com/site/jkosgrimr ... tom-assets

Dynamic hooks with custom assets

All custom assets should be included after the framework.lua or otherwise the dynamic hooks won't work with them. All cloned objects should work out of the box, but if you have created totally new assets with defineObject, you have to call fw_addHooks-function after the defineObject, IF you want to use dynamic hooks with it.

fw_addHooks(entityName,entityType,[itemSubtype])
Entity types: monster,item,alcove,blockage,door
ItemSubtypes: weapon, shield,accessory,bomb,food, missileweapon, tome,armor,cloth,herb,machinepart,potion,staff,treasure,container,key,miscitem,scroll, custom

itemSubtype defines the hook-namespace for the item and is used on various help-module functions (eg. checkType). Default value is 'custom'.

Examples

Code: Select all

defineObject{
    name='snail_king',
    class = 'Monster',
  ...
}
fw_addHooks('snail_king','monster')

defineObject{
    name='my_super_weapon',
    class = 'Item',
  ...
}
fw_addHooks('my_super_weapon','item','weapon')
- 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