alcove weight puzzle

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

alcove weight puzzle

Post by bongobeat »

Hello,

I have actually a puzzle with a script that check weight in 4 alcoves:

Please can someone tell me if there is something wrong in my script, because sometimes players don't success to this puzzle, or they have to put items in a bag to have the exact weight, because putting the items directly in the alcove won't always work.

here is the script:
when 1,2,4 and 8 kg are placed on four alcoves (alcw1 1kg, alcw2 2kg, ect..) it opens a door (iron_weight).
SpoilerShow

Code: Select all

weight = 0
weight2 = 0
weight3 = 0
weight4 = 0
finish = 0

function weightcheck()

if finish == 0 then

weight = 0
weight2 = 0
weight3 = 0
weight4 = 0

	for i in alcw1:containedItems() do
	weight = weight + i:getWeight()
	end
	for j in alcw2:containedItems() do
	weight2 = weight2 + j:getWeight()
	end
	for k in alcw3:containedItems() do
	weight3 = weight3 + k:getWeight()
	end
	for l in alcw4:containedItems() do
	weight4 = weight4 + l:getWeight()
	end
	
	check()

end
end

function check()

if finish == 0 then

if weight == 1 and 
	weight2 == 2 and 
	weight3 == 4 and
	weight4 == 8 then
	
	iron_weight:open()
	playSound("secret")
	party:getChampion(1):gainExp(800)
	party:getChampion(2):gainExp(800)
	party:getChampion(3):gainExp(800)
	party:getChampion(4):gainExp(800)
	hudPrint("800xp gained")
	finish = 1
	else
	iron_weight:close()
end

end
end
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Allanius2
Posts: 124
Joined: Mon Apr 14, 2014 10:12 pm

Re: alcove weight puzzle

Post by Allanius2 »

Using rocks for weight and calling the function from each alcove for any activity, this script works fine for me. Are you sure you're calling the function from all the alcoves? Also, what are you using for weights?

* Edit
Ok, just got the bug to occur. If i place rocks into an alcove as separate stacks, the door doesn't open. I'll continue to look into the matter.

** Edit
Ok, the problem arises when an item is placed inside an alcove that already has an item in it. In that case the Activate event is not triggered. I am not sure how to avoid this.

*** Edit
I think I have discovered the answer to your problem. if you turn on the alcoves' property Activate Always the alcoves fire the Activate event even if there is an item in the alcove. This should correct your problem. Let me know if it works for you or not.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: alcove weight puzzle

Post by bongobeat »

thanks for the help, it seems to work. I have use lots of items without bags, and the door opens itself.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Allanius2
Posts: 124
Joined: Mon Apr 14, 2014 10:12 pm

Re: alcove weight puzzle

Post by Allanius2 »

Your welcome.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: alcove weight puzzle

Post by Eleven Warrior »

Hey bro here is a easier way for Champs to get the XP:

for i = 1,4 do party:getChampion(i):gainExp(100)end

Do your script is this:

function check()

if finish == 0 then
if weight == 1 and
weight2 == 2 and
weight3 == 4 and
weight4 == 8 then

for i = 1,4 do party:getChampion(i):gainExp(800)end
hudPrint("You have gained 100 xp.")
iron_weight:open()
playSound("secret")
finish = 1
else
iron_weight:close()
end
end
end
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: alcove weight puzzle

Post by bongobeat »

Hello Eleven Warior,

thank you for your help! :)
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: alcove weight puzzle

Post by TheLastOrder »

I´m missing something here...

attempt to call method 'containedItems' (a nil value).

The alcoves are called alcw1, alcw2, etc.

Don´t you need to include something like:
Local = findEntity to make the function work???
If I put alcw1.surface it doesn´t work neither....

:?:

I´m starting to believe that somehow this function isn´t valid for LoG2.... :shock:
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: alcove weight puzzle

Post by bongobeat »

I can't tell you, but maybe it is possible
I did not try this script for log2
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: alcove weight puzzle

Post by TheLastOrder »

bongobeat wrote:I can't tell you, but maybe it is possible
I did not try this script for log2
Mmmmm... it´s probably that... :roll:

Thanks anyways!! :D
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: alcove weight puzzle

Post by bongobeat »

try this:
SpoilerShow

Code: Select all

    weight = 0
    weight2 = 0
    weight3 = 0
    weight4 = 0
    finish = 0

    function weightcheck(surface, item)

    if finish == 0 then

    weight = 0
    weight2 = 0
    weight3 = 0
    weight4 = 0


       for _,i in alcw1.surface:contents() do
       weight = weight + i:getWeight()
       end
       for _,j in alcw2.surface:contents() do
       weight2 = weight2 + j:getWeight()
       end
       for _,k in alcw3.surface:contents() do
       weight3 = weight3 + k:getWeight()
       end
       for _,l in alcw4.surface:contents() do
       weight4 = weight4 + l:getWeight()
       end
       
       check()

    end
    end

    function check()

    if finish == 0 then

    if weight == 0.1 and
       weight2 == 0.2 and
       weight3 == 1.2 and
       weight4 == 1.2 then
       
iron_weight.door:open()
       playSound("secret")
       finish = 1
       else
iron_weight.door:close()
    end

    end
    end
there is still an issue if you put a stack of (stackable) items
e.g: if you put a stack of 12 shuriken (0,1kg each, for the alcw3 or alcw4) it won't work.
It works only if you put the shurikens one by one.

I suppose it is because it has to count the items if there is stackable items.
I just think of that because Minmay gives me a script for a forge system, which check and count the stackable items.
Sorry but this comes at a point where I am lost :D
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply