StackLib
Platypus123
27 Aug 2021, 04:30Hello, I newly added StackLib and I am making a keychain in the game. But the keys that I take aren't going to the keychain. I think I did eveything true but it is still not working.
mrangel
27 Aug 2021, 11:05Can you show us the game, or the part of it that isn't working?
Platypus123
27 Aug 2021, 11:31How do I add a picture?
mrangel
27 Aug 2021, 19:58If you want to share a picture, you can upload it to a site like imgur and give us a link. However, it would be a lot more useful to see the relevant code.
Platypus123
28 Aug 2021, 04:09This is the code of the key:
<object name="Key of the Bedroom">
<inherit name="editor_object" />
<inherit name="childstack_object" />
<look>It is the old key of your bedroom.</look>
<take />
<stackparent type="object">Keychain</stackparent>
<ontake type="script">
</ontake>
<usedefaultprefix type="boolean">false</usedefaultprefix>
</object>
And this is the code of the keychain:
<object name="Keychain">
<inherit name="editor_object" />
<inherit name="stack_container" />
<alias>Keychain</alias>
<inventoryverbs type="stringlist">
<value>Look at</value>
</inventoryverbs>
</object>
Platypus123
29 Aug 2021, 07:28It's been 2 days and unfortunately I still have not received a reply. I will be pleased if you help me.
mrangel
29 Aug 2021, 10:11I think this is your problem:
<take />
Looks like you're setting the key's "take" behaviour to "Default can be taken", replacing the script that's added by childstack_object.
Try removing that property from the key.
Platypus123
29 Aug 2021, 16:56I did it but there is still a take button but it is not working. The key isn't disappearing or going to keychain. It's just giving me you take it message.
mrangel
29 Aug 2021, 18:47I did it but there is still a take button but it is not working. The key isn't disappearing or going to keychain. It's just giving me you take it message.
Is there no longer a take
attribute on the key?
"You take it" should only appear if you have that <take />
attribute (which corresponds to the "can be taken" checkbox in the editor).
Platypus123
29 Aug 2021, 20:12There is, but it is "false"
mrangel
30 Aug 2021, 01:09There is, but it is "false"
That's your problem then.
If it has a take
attribute that is true, it follows the default behaviour for an object that can be taken.
If it has a take
attribute that is false, it follows the default behaviour for an object that can't be taken.
If it has a take
attribute that is a script, it will run that script when the player tries to take it.
If it doesn't have a take
attribute, then it will inherit this attribute from its types.
The take
attribute of the childstack_object
type adds it to the appropriate stack.
In order to use this attribute, the object needs to not have a take
attribute of its own.
I believe that (because of an oddity in the way the editor handles types), if you click the "Can be taken" box in the editor (either to select it or deselect it) then you will need to use code view to remove the take
attribute again; as the editor doesn't give a way to entirely remove an attribute.
Alternatively, you could give it a "Run a script" take attribute that is a copy of the one from the childstack_object type:
if (this.alias = null) {
this.alias = this.name
}
container = this.stackparent
this.parent = container
SetStack(container)
if (this.takemsg = null) {
msg(DynamicTemplate("TakeSuccessful", object))
}
else {
msg (this.takemsg)
}
Platypus123
30 Aug 2021, 06:23I am taking this error but it is working:
Error running script: Error compiling expression 'container.parent = Stack Containers': Unknown object or variable 'Stack Containers'
I am taking this error both when I take it and look at it in the keychain. Also, before this stack thing, I was using "if player is carrying object" script to pass through a door. But it isn't working now because the key is in the keychain. How can I make an alternative door system?
mrangel
30 Aug 2021, 08:34There needs to be an inaccessible room named Stack Containers
, where stack containers (such as the keyring) are stored until the player has items that can go in them.
Platypus123
30 Aug 2021, 09:25Thanks, it worked. What about the alternative door system?
mrangel
30 Aug 2021, 14:06My first guess would be changing your if statement to use an expression like Contains (Keychain, Key of the Bedroom)
to check if the key is on the chain.
Platypus123
30 Aug 2021, 16:50Thanks, it worked. Also I will be very happy if you look at that topic of mine:
http://textadventures.co.uk/forum/quest/topic/2-uxyot1n0cw2p-70em3yq/monsters-in-combatlib