Page 1 of 1

alcove weight puzzle

Posted: Fri Jun 27, 2014 10:14 pm
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

Re: alcove weight puzzle

Posted: Sat Jun 28, 2014 12:57 am
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.

Re: alcove weight puzzle

Posted: Sat Jun 28, 2014 10:16 am
by bongobeat
thanks for the help, it seems to work. I have use lots of items without bags, and the door opens itself.

Re: alcove weight puzzle

Posted: Sat Jun 28, 2014 10:36 am
by Allanius2
Your welcome.

Re: alcove weight puzzle

Posted: Thu Jul 03, 2014 9:30 am
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

Re: alcove weight puzzle

Posted: Sun Jul 06, 2014 6:27 pm
by bongobeat
Hello Eleven Warior,

thank you for your help! :)

Re: alcove weight puzzle

Posted: Fri Jan 02, 2015 6:55 pm
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:

Re: alcove weight puzzle

Posted: Fri Jan 02, 2015 8:07 pm
by bongobeat
I can't tell you, but maybe it is possible
I did not try this script for log2

Re: alcove weight puzzle

Posted: Sat Jan 03, 2015 6:23 am
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

Re: alcove weight puzzle

Posted: Sat Jan 03, 2015 1:26 pm
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