Page 202 of 396

Re: Ask a simple question, get a simple answer

Posted: Fri May 05, 2017 5:04 am
by gmsantashelper
Interesting. The readme for alpha008 of grimtk says:
3. Open your dungeon in the Dungeon Editor (or reload it) and find the object "grimtk" in the asset
browser. Add a single instance of this to your dungeon (anywhere). This will add the required scripts
to your dungeon.
In reality it must be placed at (0,0,0) or I get the crash. I had it placed in the starting location, which was not actually 0,0,0. Moved it to 0,0,0 and now it works just fine again. Fairly certain it used to work where it was. Very odd. Guess this ended up being a simple problem after all. :roll:
Thanks for the help everyone.

Re: Ask a simple question, get a simple answer

Posted: Tue May 23, 2017 11:39 am
by ColdDeadStone
I have a simple question and would be happy about a simple answer and maybe a solution! Why is this always false? a and b are Equal!

Code: Select all

function vectorcheck()
local a = vec(6.289999, 2.240000, 9.000000, 0.000000)
local b = vec(6.289999, 2.240000, 9.000000, 0.000000)

	if a == b then
		print("true")
	else
		print("false")
	end
end
Thanks for reading!

Re: Ask a simple question, get a simple answer

Posted: Tue May 23, 2017 1:57 pm
by akroma222
ColdDeadStone wrote:I have a simple question and would be happy about a simple answer and maybe a solution! Why is this always false? a and b are Equal!

Code: Select all

function vectorcheck()
local a = vec(6.289999, 2.240000, 9.000000, 0.000000)
local b = vec(6.289999, 2.240000, 9.000000, 0.000000)

	if a == b then
		print("true")
	else
		print("false")
	end
end
Thanks for reading!
Im not a vector savvy person, however, if you change your function to this:
SpoilerShow

Code: Select all

function vectorcheck()
local a = {6.289999, 2.240000, 9.000000, 0.000000}
local b = {6.289999, 2.240000, 9.000000, 0.000000}

   if a == b then
      print("true")
   else
      print("false")
   end
end
(a and b are now just tables) ... then it works as you wanted

Also read up on the vector functions here
viewtopic.php?f=22&t=13925

Akroma

Re: Ask a simple question, get a simple answer

Posted: Tue May 23, 2017 2:13 pm
by Leki
ColdDeadStone wrote:I have a simple question and would be happy about a simple answer and maybe a solution! Why is this always false? a and b are Equal!

Code: Select all

function vectorcheck()
local a = vec(6.289999, 2.240000, 9.000000, 0.000000)
local b = vec(6.289999, 2.240000, 9.000000, 0.000000)

	if a == b then
		print("true")
	else
		print("false")
	end
end
Thanks for reading!
There is no built-in function for comparing tables by contents. You'll have to write your own. Smth like (untested, but you see the point I guess):

Code: Select all

function is_table_equal(t1,t2,ignore_mt)
   local ty1 = type(t1)
   local ty2 = type(t2)
   if ty1 ~= ty2 then return false end
   -- non-table types can be directly compared
   if ty1 ~= 'table' and ty2 ~= 'table' then return t1 == t2 end
   -- as well as tables which have the metamethod __eq
   local mt = getmetatable(t1)
   if not ignore_mt and mt and mt.__eq then return t1 == t2 end
   for k1,v1 in pairs(t1) do
      local v2 = t2[k1]
      if v2 == nil or not is_table_equal(v1,v2) then return false end
   end
   for k2,v2 in pairs(t2) do
      local v1 = t1[k2]
      if v1 == nil or not is_table_equal(v1,v2) then return false end
   end
   return true
end

Re: Ask a simple question, get a simple answer

Posted: Tue May 23, 2017 2:19 pm
by akroma222
Another way to do the comparing...
SpoilerShow

Code: Select all

function vectorcheck()

	local v1 = vec(6.289999, 2.240000, 9.000000, 0.000000)
	local v2 = vec(6.289999, 2.240000, 9.000000, 0.000000)

	if vec.isvec(v1) and vec.isvec(v2) then
		for i = 1,4 do
			if vec.__index(v1, i) ~= vec.__index(v2, i) then
	      		print("false")
				return false
			end
		end   		
		print("true")
		return true
	else
		print(iff(vec.isvec(v1),"v2","v1").." is not a vector")
		return
	end
		
end

OR if you want it to be a general function that can compare 2 vectors (passed as v1 and v2)...
SpoilerShow

Code: Select all

function vectorcheck(v1, v2)
	
	if not v1 or not v2 then return end
	
	if vec.isvec(v1) and vec.isvec(v2) then
		for i = 1,4 do
			if vec.__index(v1, i) ~= vec.__index(v2, i) then
	      		print("false")
				return false
			end
		end   		
		print("true")
		return true
	else
		print(iff(vec.isvec(v1),"v2","v1").." is not a vector")
		return
	end
		
end

Re: Ask a simple question, get a simple answer

Posted: Tue May 23, 2017 2:54 pm
by ColdDeadStone
Uhh, that's a lot of info's! Thank you very much for answering me @akroma222 & @Leki! I will work through these Examples! Is not as easy as I thought but anyway, thanks again and have a nice Day!

Re: Ask a simple question, get a simple answer

Posted: Wed May 24, 2017 3:17 am
by minmay
The most concise way to check if two vectors are equal is to check if vec.length(a-b) == 0.

Code: Select all

local a = vec(6.289999, 2.240000, 9.000000, 0.000000)
local b = vec(6.289999, 2.240000, 9.000000, 0.000000)

   if vec.length(a-b) == 0 then
      print("true")
   else
      print("false")
   end
Alternatively, if you want to use the == operator to compare vectors for equality, run this in your init.lua or a file imported by it (NOT from a ScriptComponent):

Code: Select all

vec.__eq = function(a,b) return a[1]==b[1] and a[2]==b[2] and a[3]==b[3] and a[4]==b[4] end
(This method is a little more efficient than calling length).
You can then use a == b to check whether vectors a and b have the same contents.
Note that this change will persist until the game is closed, so it can carry into other dungeons.

Re: Ask a simple question, get a simple answer

Posted: Sun May 28, 2017 9:39 pm
by Torquemada
Here's my simple question, I hope the answer is as simple
I want a door to open when a monster group is dead. It's simple with a single monster but the group doesn't have onDie hook

Re: Ask a simple question, get a simple answer

Posted: Sun May 28, 2017 11:28 pm
by Isaac
Torquemada wrote:Here's my simple question, I hope the answer is as simple
I want a door to open when a monster group is dead. It's simple with a single monster but the group doesn't have onDie hook
A quick—but not scrupulously accurate way, is to track the monsters with a set, and consider them dead as you mark them off the list.
(This doesn't actually check to see if they're dead, but they shouldn't be alive either. There are cases in Grimrock where a dead monster can still exist.)

Code: Select all

--List the monsters in the set here
set = {	"zarchton_1",
		"zarchton_2",	
		"zarchton_3",
		"zarchton_4",
	}

--Adds onDie hooks at load
for x = 1, #set do
	local monster = findEntity(set[x])
	if monster then
	   monster.monster:addConnector("onDie", self.go.id, "deadCheck")
	end
end

--Gets called by each monster as they die
function deadCheck(caller)
	
	--No entries, means they are all dead
	if #set <= 1 then
		dungeon_door_wooden_1.door:open()
		return
	end
	
	--removes the dying monster from the set
	for k,v in pairs(set) do
		if v == caller.go.id then
			table.remove(set, k)
			break
		end
	end	
end
Fill the list at the top with your own monster id strings, and change the id of the door to match yours.

*I just did a very minor update, that bypasses the table operation for the last monster. You can use the updated script, but the previous script would still work fine.

Re: Ask a simple question, get a simple answer

Posted: Mon May 29, 2017 5:34 am
by minmay
Pretty sure by "monster group" they meant a MonsterGroupComponent, not several different manually placed monsters.