Page 1 of 1
Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 5:29 am
by akroma222
Hellooo!
I require a bit of direction here folks...
I have 3 alcoves and 3 gems (red, green and blue) with 2 secret doors nearby. I want there to be 2 different combinations (of coloured gems in alcoves) to open the secret doors.
So far, I have set up 1 script for each alcove for 1 combination (for example):
function gemCheckRed()
local itemFound = false
for i in alcoveGemSecret1:containedItems() do
if i .name == "red_gem" then
itemFound = true
end
end
if itemFound then
gemCounter:increment()
end
end
and these scripts are connected to a counter set to 3 (event>activate, action>increment) and also to the appropriate script (event>any, action>red gem check). The counter is then connected to a secret door.
The secret door wont open.
Any help would be muchly appreciated. I have never modded or scripted anything before so this learning curve has been quite steep.
Thank you!!!
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 12:42 pm
by Komag
You're starting with a VERY complex scripting puzzle here. It would take me a while to figure this one out, so I'm not going to do it right now, but I would suggest you practice some simpler versions of what you want and make sure each step works before adding another aspect. Also, add in "print" commands at different points and see if they happen, which will help you "debug" the process.
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 1:19 pm
by akroma222
Hahaha! Cheers man, I am fairly out of my depth here, I am not a modders/programmers bootlace..... I don't even know how unreasonable the questions I am asking are!! LOL
Ta for the debugging advice, let me know if you stumble upon something of a similar vein
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 1:33 pm
by Komag
Oh I'm sure what you want can be done, it's just a matter of getting a strong grasp on how everything really works under the hood first by learning other examples
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 1:45 pm
by crisman
I did the same puzzle, but with 4 gems and 7 alcoves.
And I've used two script, one complicate, and a simple one.
it was the second puzzle I've worked on... and it's pretty complicated, yes.
Probably now I think I'll write it in another way, but it's working, so I won't rewrite it... (any suggestion are accepted thought!)
Here how I made it:
function doorOpen()
for i in alcoveRed:containedItems() do
if i.name == "red_gem" then
for i in alcoveGreen:containedItems() do
if i.name == "green_gem" then
for i in alcoveYellow:containedItems() do
if i.name == "yellow_gem" then
for i in alcoveBlue:containedItems() do
if i.name == "blue_gem" then
door:open()
end
end
end
end
end
end
end
end
end
This is the simpliest one.
Remember to connect the alcove, and check Always on and the type of action should be "any"
the complex one require only one object on the alcove (the one above just check if there is the desiderd item), but you can freely place something else on the others. The important is that the right alcoves there are only the correct gems.
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 2:42 pm
by akroma222
Delightful!! Works like a charm
Many thanks Crisman, that code if fairly simple indeed (even I know what's going on!) hehehe
Scripting and coding is so foreign to me, but a few days in and I am managing some nifty puzzles..... The problem is my creativity seems to be exceeding my skill in making it all happen lol
Thanks to both of you!!
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 2:52 pm
by Filipsan
Try this
Code: Select all
function testAlcove()
local red_gem_in = hasItem(alcoveRed,"red_gem")
local green_gem_in = hasItem(alcoveGreen,"green_gem")
--yellow_gem_in = hasItem(alcoveYellow,"yellow_gem")
local blue_gem_in = hasItem(alcoveBlue,"blue_gem")
print("red: " .. tostring(red_gem_in))
print("green: " .. tostring(green_gem_in))
print("blue: " .. tostring(blue_gem_in))
if(red_gem_in and green_gem_in and blue_gem_in) then
dungeon_door_iron_1:open()
else
dungeon_door_iron_1:close()
end
end
function hasItem(alcove,item_name)
if( alcove:getItemCount() == 1) then
for i in alcove:containedItems() do
if i.name == item_name then
return true
end
end
end
return false
end
EDIT: Added prints, added item count check
Re: Help Req! - 3 gems(r/g/b)-3 alcoves-2 doors(diff combos)
Posted: Sat Oct 06, 2012 4:05 pm
by crisman
akroma222 wrote:Delightful!! Works like a charm
Many thanks Crisman, that code if fairly simple indeed (even I know what's going on!) hehehe
Scripting and coding is so foreign to me, but a few days in and I am managing some nifty puzzles..... The problem is my creativity seems to be exceeding my skill in making it all happen lol
Thanks to both of you!!
No problem!! Glad it helped!
@filipsan
Ah, that's a good one!
I've programmed this puzzle when I knew only if statement
(the for statement didn't understand what is was doing at the time, but it was working, and that was enough)