[Library] - GrimQ - v1.4.3

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: [Library] - GrimQ - a query library for Grimrock and Lua

Post by JKos »

That sounds really neat and useful -> to exploring the sources.
- 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
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: [Library] - GrimQ - a query library for Grimrock and Lua

Post by Xanathar »

I will probably sound like a total stupid whatever, but what does "that" do that the current scripting language doesn't ?
What is the interest of this for me (us?), simple lua users ?
Legit question :)
As it's written using the editor itself, of course it doesn't do anything you couldn't do otherwise. It's just that querying entities is something I find I'm doing all the time in my mod - counting monsters, checking items in alcoves, find an empty spot in inventories, checking champion statuses, etc. - and so taking some shortcut was worth it. A side effect is that - for some queries - it might be easier to write a correct version this way, as you focus on the query itself instead of getting the for loop right (for example, checking alcoves with multiple items). Consider, however, that I'm writing similar queries in other languages all the time for my job, so my perception on that topic is surely skewed! :?

IMHO if you have already used LINQ in other programming languages (or maybe even SQL), in the past you can get a grasp on it in a short time and start writing those queries almost immediately - in this case it's worth pursuing as time gained would quickly (probably?) recover the time spent learning.
If you instead must start from scratch, I don't honestly know it it's worth the investment :oops:
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: [Library] - GrimQ - a query library for Grimrock and Lua

Post by cromcrom »

Ok, thanks for the clear answer. I will probably stick to LUA as it is.
A trip of a thousand leagues starts with a step.
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: [Library] - GrimQ - a query library for Grimrock and Lua

Post by Xanathar »

I was just thinking:

at the end of the file, there are a ton of useful methods - isMonster, isDoor, loadItem, saveItem.
They don't require the rest and may be useful even outside the query thing. Feel free to cut/paste them where you need :)

For example a trick I use is:

container:addItem(loadItem(saveItem(item)))
item:destroy()

that moves an item to a container or alcove/altar, so that I can design my notes/scrolls visually and then move them into a sack, and then maybe the sack onto an altar without getting insane in the process :)
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: [Library] - GrimQ - a query library for Grimrock and Lua

Post by Xanathar »

Version 1.1 released, with many many changes to the grimrock helper methods and thingies, have a look even if you don't plan to use queries (they are together as the new things are based themselves on queries).

for queries:
  • Set-theory methods - distinct, union, except (difference), intersection
  • Added custom comparator function to contains
  • fromPartyInventoryEx, fromChampionInventoryEx, fromEntitiesInArea, fromEntitiesAround, fromEntitiesForward, fromEntitiesInWorld
  • New filters: has and match to easily test id and name against patterns or any attribute against a known value
for generic use:
  • Enumeration - gives meaningful names to inventory slots and facing directions
  • isScript - check if an entity is a scripting entity
  • copyItem(item) – creates a copy of an item
  • moveFromFloorToContainer(container, item) – moves an item from the floor to the specified container
  • moveItemsFromTileToAlcove(alcove) – moves all items in the same tile of the specified alcove, into the alcove itself
Finally, this introduces "automatic objects" to simplify dungeon creation:
  • Any secret whose id starts with “auto_secret” is activated automatically when the party steps on it
  • An “auto_printer” object is provided, when the party steps over it its content are hudPrint-ed.
  • Any torch holder whose name starts with “auto_” is given a torch
  • Any alcove whose name starts with “auto_” is filled with all the items found in the same tile
  • Any scripting entity containing a method named “autoexec” have that method called at startup. This happens after all the scripting entities have been loaded (and thus is better than code outside of any entity).
These objects are defined (where needed) in a “grimq_objects.lua” file. At the top of the file, there is a “__itemstoautomate” table containing all items which will be cloned in an automated version. Feel free to change at your pleasure.

NOTE: An additional setup step has been introduced. As per the chests, there is a MAXLEVEL variable to be updated with the maximum level of your dungeon, until the new version of Grimrock is released with the getMaxLevel() function (thanks petri ;) )
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: [Library] - GrimQ - a query library for Grimrock&Lua - v

Post by JKos »

Really nice new features and you gave me some ideas + I like the direction where this is heading.

ps. Your code is really clean and easy to read, obviously well thought.
- 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
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: [Library] - GrimQ - a query library for Grimrock&Lua - v

Post by Xanathar »

Code: Select all

Your code is really clean and easy to read, obviously well thought.
Thanks! :)

And I totally need to integrate your framework in my dungeon - the ability to add hooks and dynamic data to entities are awesome!
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

[Library] - GrimQ - a query library for Grimrock&Lua - v1.2

Post by Xanathar »

Hi all, version 1.2 is out.

It has major fixes and reorganizations inside, the first of which is the move to GoogleCode as SourceForge was overkill for this kind of project (<rant>and totally unintuitive to use, it's still the same as 10 years ago if not worse </rant>).

The new download link is: http://code.google.com/p/lualinq/

Changes:
"from" detects a GrimQ structure and inteprets it correctly, plus all methods taking a second LuaLinq now can take anything you can feed a "from" method with

This mean you can use arrays in calls to except, zip, etc. without converting to GrimQ objects first.

"select" method accepts a property name instead of a selector function / "where" method accepts a property name and a value instead of a predicate


This means you can now write:

Code: Select all

	
     grimq.from(allEntities(1))
		:where("name", "secret")
		:select("id")
		:foreach(print)
reverseFacing, getChampionFromOrdinal, isToorumMode, dezombifyParty
Utility functions of recurrent use. Nothing to write home about

string functions
strformat(string, ...) – transform the string by replacing tokens starting with $ with an appropriate substitution text:
-- $1.. $9 -> are replaced with the optional parameters which can be passed to the function
-- $champ1..$champ4 -> are replaced with name of champion of the appropriate slot
-- $CHAMP1..$CHAMP4 -> are replaced with name of champion of the appropriate ordinal
-- $rchamp -> a random champion
-- $RCHAMP -> a random champion which is alive and enabled

for example: hudPrint(strformat("Hello $RCHAMP")) - will print Hello followed by a random champion name everytime it's called.

strstarts(string,start) – returns true if string starts with the “start” string
strends(string,end) – returns true if string starts with the “end” string
strmatch(string, pattern) – returns true if the string matches the Lua pattern specified (see http://lua-users.org/wiki/PatternsTutorial and http://www.lua.org/pil/20.2.html)

Auto objects
If AUTO_ALL_SECRETS option is enabled, all secrets are automatic. Hud Printer uses strformat so you can put champions names there.

JKos framework integration
The integration is OPTIONAL.
The integration with the awesome JKos framework offers:
  • Simplified JKos framework setup (no need of defining the logfw_init entity in the dungeon)
  • Automatic hooks (see autohooks) can be defined in scripting entities
  • Initialization order features – the autoexec method of scripting entities will be called after both GrimQ and JKos framework are initialized and ready
  • Non-delayed initialization – the initialization of JKos framework does not use a timer at this moment, in grimq
To setup:
  • Setup GrimQ and set its USE_JKOS_FRAMEWORK option to true
  • Follow the setup instructions at https://sites.google.com/site/jkosgrimrock2/home but do NOT create the logfw_init entity
  • Put any code adding hooks etc. in an autoexec method in any scripting entity you want.
Advantages:
As said, the advantage is that autoexec() methods of scripting_entities are called only when all the other scripting entities are loaded AND the jkos framework is completely initialized.
As a bonus, one can write automatic hooks. For example if you put:

Code: Select all

autohook =
{
	party =
	{
		onPickUpItem = function(self, item)
			print("onPickUpItem")
		end,

		onMove = function(self, direction)
			print("onMove")
		end,

		onTurn = function(self, direction)
			print("onTurn")
		end,
	}
}
in an entity, those hooks are automatically installed at startup.


Thanks again to JKos for such an awesome framework.

Now let's try to work on the mod for 2 days straight without saying "mmh maybe this could be generalized and moved in a library..." :lol:
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: [Library] - GrimQ - a query library for Grimrock&Lua - v

Post by JKos »

Wow, that's cool. I was going to add GrimQ to my framework as a core module but you were faster :D Thanks. Autohooks are nice addition. I have try this new version soon.
- 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: [Library] - GrimQ - a query library for Grimrock&Lua - v

Post by Diarmuid »

Thanks a lot! Your both libraries have done marvels in streamlining my scripting, I couldn't have done my recent fancy scripts without. It's great to see them integrated in a better way.
Post Reply