Hello,
I've created this item. My problem with "open" function. It displays my message but it doesn't display the item in container.
Thanks per advance
alias: "cylindre de plastacier",
scenery: false,
loc: "dantoine_enclave_chambre",
closed: true,
defArticle: "un",
indefArticle: "un",
examine:function(isMultiple) {
if (this.closed)
{
msg(prefix(this, isMultiple) + "Un cylindre en plastacier contenant des objets personnels.");
}
else
{
msg(prefix(this, isMultiple) + "Un cylindre en plastacier contenant des objets personnels. A l'intérieur, vous trouvez : " + formatList(this.getContents(world.LOOK), {lastJoiner:lang.list_and, article:INDEFINITE}) + ".");
}
},
open:function(isMultiple) {
if (!this.getContents(world.LOOK).length > 0)
{
msg("Vous ouvrez le cylindre de plastacier. A l'intérieur, vous ne trouvez rien.");
}
else
{
msg("Vous ouvrez le cylindre de plastacier. A l'intérieur, vous trouvez : " + formatList(this.getContents(world.LOOK), {lastJoiner:lang.list_and, article:INDEFINITE}) + ".");
}
}
});```
Hello.
Did you make the item OPENABLE()
, or did you make it a CONTAINER(true)
?
(It should be a CONTAINER(true)
but not OPENABLE()
in your code.)
Does this example help?
(It might help, unless you want to control whether or not it actually opens. I'm assuming you simply want something extra to happen once it is opened.)
createItem("box", CONTAINER(true), {
loc:"lounge",
examine:"A perfectly normal box, currently {if:box:closed:closed:open}.",
onOpen:function(){
msg("This text was printed by the <b><code>onOpen</code></b> function!");
}
});
createItem("message",TAKEABLE(),{
loc:"box",
examine:function(){msg("The message reads: \"Hello, world!\"");},
read:function(){
if (typeof(this.examine)==="string"){
msg(this.examine);
}else if (typeof(this.examine)==='function'){
this.examine();
}else{
errormsg("Something when wrong in the 'message' item's 'read' script!");
}
},
});
It works but I've a double message : its from system Quest (first) and the mine (second).
Quest - Language : You open le coffre personnel. A l'intérieur, vous trouvez : votre Bure Jedi.
My Message in function : Vous ouvrez le coffre personnel. A l'intérieur, vous trouvez : votre Bure Jedi.
Thanks for your help.
Ah. I believe I should have used openMsg
rather than onOpen
.
createItem("box", CONTAINER(true), {
loc:"lounge",
examine:function(isMultiple) {
if (this.closed)
{
msg(prefix(this, isMultiple) + "Un cylindre en plastacier contenant des objets personnels.");
}
else
{
msg(prefix(this, isMultiple) + "Un cylindre en plastacier contenant des objets personnels. A l'intérieur, vous trouvez : " + formatList(this.getContents(world.LOOK), {lastJoiner:lang.list_and, article:INDEFINITE}) + ".");
}
},
openMsg:function() {
if (!this.getContents(world.LOOK).length > 0)
{
msg("Vous ouvrez le cylindre de plastacier. A l'intérieur, vous ne trouvez rien.");
}
else
{
msg("Vous ouvrez le cylindre de plastacier. A l'intérieur, vous trouvez : " + formatList(this.getContents(world.LOOK), {lastJoiner:lang.list_and, article:INDEFINITE}) + ".");
}
},
});
createItem("message",TAKEABLE(),{
loc:"box",
examine:function(){msg("The message reads: \"Hello, world!\"");},
read:function(){
if (typeof(this.examine)==="string"){
msg(this.examine);
}else if (typeof(this.examine)==='function'){
this.examine();
}else{
errormsg("Something when wrong in the 'message' item's 'read' script!");
}
},
});