Page 6 of 10
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 7:47 pm
by Redweaver
I'm wanting to use the magic_orb to socket in the mouth...so I'm guessing this:
Code: Select all
cloneObject{
name = "mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
}
...needs to be this:
Code: Select all
cloneObject{
name = "mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_orb")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
}
?
Major thanks again to everyone of you helping me out here. The dungeon is about halfway done, I should be able to put it up for playtesting by the weekend!
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 7:57 pm
by msyblade
nailed it. But be aware that the "stringfind" part of it is to make it where ALL objects named "anything_orb" will fit. (Useful trick with some later scripts you might try).
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 8:13 pm
by Redweaver
Well, unintended concequences. Now it takes the orb, but it won't take gems. I want the player to be able to put the wrong item in there...evil DM need to let the player fail, and get damaged!
Can I take this:
Code: Select all
cloneObject{
name = "redweaver_mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_orb")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
}
and add ', or "_gem") to the "local a, b = string.find" bit? Or just copy/paste that line and put it right underneath with "_gem" instead of "_orb"? Will that make it fit either?
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 8:24 pm
by msyblade
(item.name, "_orb", "_gem") should work for you then
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 8:27 pm
by Redweaver
msyblade wrote:(item.name, "_orb", "_gem") should work for you then
Oh, boy, it did not like that one bit! Popped a window with a huge error and a suggestion that I email the error log to almosthuman games. And the editor crashed.
Code: Select all
cloneObject{
name = "redweaver_mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_orb")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
}
Though if I just doubled up and made the second function look for a gem that might work. Now it will only accept gems.
I know I can just brute force it by making
another cloned mouth socket that looks for gems instead and layer them in the editor, but that's not very elegant.
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 8:41 pm
by msyblade
Ha! perhaps the one string find cannot take two strings? Try your second idea then. You really have your head around it, you're usually on the right track. before long, you'll be a scripting guru!
Code: Select all
cloneObject{
name = "mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0,
local a, b = string.find (item.name, "_orb")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0,
end,
end,
}
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 8:46 pm
by msyblade
remember that u do not need the string find part. that is just to make it accept all of ONE type. Check out Neikuns,batty and crismans Mouth WEAPON socket script:
defineObject{
name = "mouth_socket_weapon",
class = "Alcove",
anchorPos = vec(0, 1.1, -0.38),
anchorRotation = vec(0,90,0),
targetPos = vec(0, 1.1, -0.38),
targetSize = vec(0.3, 0.3, 0.3),
placement = "wall",
onInsertItem = function(self, item)
local allowed = {"long_sword", "flameheart", "shaman_staff", "nex_sword", "dismantler", "lightning_blade",
"lightning_blade_empty", "legionary_spear", "fire_blade", "fire_blade_empty", "dagger", "whitewood_wand",
"ancient_axe", "great_axe", "torch", "torch_everburning", "arrow", "cold_arrow", "cold_quarrel", "fire_arrow", "fire_quarrel", "poison_arrow",
"poison_quarrel", "quarrel", "shock_arrow", "shock_quarrel", "assassin_dagger", "battle_axe","cudgel","fist_dagger", "knoffer",
"throwing_knife", "knife", "machete","shuriken","venom_edge", "venom_edge_empty", "lightning_rod", }
for i = 1, #allowed do
if item.name == allowed then
return item.name == allowed and self:getItemCount() == 0
end
end
end,
editorIcon = 92,
}
important part being:
onInsertItem = function(self, item)
local allowed = {"long_sword", "flameheart", "shaman_staff", "nex_sword", "dismantler", "lightning_blade",
"lightning_blade_empty", "legionary_spear", "fire_blade", "fire_blade_empty", "dagger", "whitewood_wand",
"ancient_axe", "great_axe", "torch", "torch_everburning", "arrow", "cold_arrow", "cold_quarrel", "fire_arrow", "fire_quarrel", "poison_arrow",
"poison_quarrel", "quarrel", "shock_arrow", "shock_quarrel", "assassin_dagger", "battle_axe","cudgel","fist_dagger", "knoffer",
"throwing_knife", "knife", "machete","shuriken","venom_edge", "venom_edge_empty", "lightning_rod", }
for i = 1, #allowed do
if item.name == allowed then
return item.name == allowed and self:getItemCount() == 0
end
end
end,
}
So u can define EXACTLY what u want to fit into ANYTHING 
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 8:53 pm
by Redweaver
Error. ...objects.lua:35: 'end' expected (to close function at line 32) near local
Code: Select all
cloneObject{
name = "redweaver_mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_orb")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
end,
}
I put in a second 'end' and even remembered the comma this time.
Code: Select all
cloneObject{
name = "redweaver_mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_orb")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0
end,
}
Didn't work either. ...objects.lua:36: unexpected symbol near 'local'.
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Wed Dec 05, 2012 9:15 pm
by Redweaver
This in objects.lua:
Code: Select all
cloneObject{
name = "redweaver_mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local allowed = {"magic_orb", "red_gem", "green_gem", "blue_gem"}
for i = 1, #allowed do
if item.name == allowed[i] then
return item.name == allowed[i] and self:getItemCount() == 0
end
end
end,
}
And this as a script entity:
Code: Select all
function checkAlcoveForItems()
local itemFound = false
if redweaver_mouth_socket_1:getItemCount() == 0 then
itemFound = false
else
for i in redweaver_mouth_socket_1:containedItems() do
if i.name == "magic_orb" then
itemFound = true
break
else
spawn("fireburst", party.level, party.x, party.y, 0)
itemFound = false
break
end
end
end
if itemFound then
playSound("level_up")
prizedoor:open()
else
prizedoor:close()
end
end
Worked! Woo Haaa!

Remember to point the cloned mouth_socket at the script and set the connector to "any" so it will close the door again if you remove the magic_orb.
Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Thu Dec 06, 2012 7:58 pm
by Redweaver
Done and nearly ready for submission! I need a playtester or two if anyone has time. I need to know how to make a script pause for a second or two before moving to the next command (I tried sleep(1) but it gave me an error, so I must have used it wrong somehow).
And I need a beer.
