Page 1 of 1

check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 5:15 pm
by Komag
I tried to set up a "nice" way to check player's Grimrock version to make sure they aren't using 1.3.1, because many things in Master Quest require 1.3.6 or higher. I first set up a little room with a scroll that if some other script didn't work right they would get teleported to and read the scroll telling to get a patch and update their Grimrock, but then nothing I tried to set up worked out that way.

So I ended up just creating a crash test - first thing the dungeon does is try to setPosition a snail, and if the player is using 1.3.1 it will crash. The trick is that I named the script entity and the function VERY descriptively, so the crash report will be as helpful as possible: :mrgreen:

Image

(This will be going into my first updated version of Master Quest)

Re: check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 5:41 pm
by JohnWordsworth
In your test to see if you should teleport them to the room of 'you need to upgrade' could you just check if one of the new methods does what it is supposed too?

I forget exactly what was added when, but for instance you could see if the method getStatistic exists and thst getStatistic ('playTime') returns a value greater than zero.

If there are no global methods that were specifically added in 1.3.6 then you could write a very tiny line in one of the new hooks that sets a global variable, isVersionSupported = true. Then you could check for that variable after you know that function should have been called.

Re: check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 6:04 pm
by Komag
That's exactly the sort of thing I was trying to do, but I discovered that trying any method that doesn't exist causes a crash, period.

Here is the info on all the good stuff added in 1.3.6:
viewtopic.php?f=14&t=4530

I thought about trying to use one of the new hooks, but never explored that route, maybe I'll try it.

Re: check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 7:07 pm
by JohnWordsworth
Ahh - good find, I was on my phone for my previous post, so I wasn't really in the mood for searching for the change list (especially as my Android phone makes it rather difficult to post here sometimes - grr). Back on the laptop now though!

Suggestions...

1. So you should be able to test for the presence of the getStatistic method without actually calling it.

Code: Select all

if ( getStatistic ) then 
  print("Version 1.3.6 or above");
else
  print("Below Version 1.3.6");
end
2. If the global methods are injected into the lua state using a method that I'm not sure about (some sort of global method look-up instead of added in as C funcs) then you might have to use the onHook method, but I'm pretty confident (1) above should work.

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",

  onDrawGui = function (g) 
    isVersion136 = true;
  end
}
However, this second solution makes me feel queasy as the idea of running that every frame of the mod just to find out the value once seems untidy. A less ugly version would be to override an item's Item:onEquipItem(champion, slot) and make the user equip it I guess.

Re: check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 7:10 pm
by Komag
Yes, I had been thinking of just quickly adding a custom defined item to some inventory slot and then immediately destroying it, and using either onEquipItem or onUnequipItem. But I'll try the first idea first, I never thought of seeing if a method exists like that.

Re: check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 7:42 pm
by Xanathar
I tried to do it that way.. and it should work.
The problem is, you must make sure no script gets executed with those new methods (including startup scripts, timers, etc.).
I failed at that :? and for some dungeons (mine :lol: ) it can be a major pain.

Re: check player's Grimrock for version 1.3.6 or higher...

Posted: Wed Mar 20, 2013 8:18 pm
by Komag
Ah, it works great! Now I can just send players to a room with gentle scroll telling them to patch their game, much better than making the game CRASH!

Thanks for the help, this is much improved :)

Code: Select all

function _checkVersion() -- trig by dungeonStart() via timer 0.05s
  if getStatistic then
     pr.nt("You have Grimrock v1.3.6 or later, good")
     return true
    else
     pr.nt("old Grimrock version detected, party stranded!")
     hudPrint("Uh oh, you have an outdated version of Grimrock, party stranded!")
     spawn("teleporter",1,party.x,party.y,2)
      :setTeleportTarget(0,30,2)
     return false
  end
end
When dungeonStart() calls this _checkVersion(), if it gets a false, it will not continue with all the other stuff it does, things that would otherwise use methods the player doesn't have and cause a crash.