Clone item when using Pixies StackLib

Forgewright
15 Apr 2020, 14:58

The last line on the page of the instructions says the library would work with clonable items too and that's it. I assume I will have to change the Take script for the item I want to take and clone, as the library has no mention of clones.

so I use:CloneObjectAndMove (flower, player) but it just keeps putting the item in my inventory.
if I use:CloneObjectAndMove (flower, Stackable Container) It does not show in inventory.
if I use:CloneObjectAndMove (flower, flower_container )which is in the Stackable Container, nothing shows.

Where do I send the clone?
To the Stack Container?
To the named stack container in the Stack Container?
To the player?

I made the main Stack Container a room by itself away from player access.


mrangel
15 Apr 2020, 16:21

For some reason, this stack library uses the take and drop commands to add and remove stuff from the library, rather than changedparent. Therefore it will ignore the stacking functionality if an object is added to the inventory by a script, or by any means other than the default stacking script.

I assume you have an object which is trying to give the player a flower; I think there's two different ways to do this, based on skim-reading the code.

Method 1:

  • CloneObjectAndMove (flower, flower.stackparent) - adds the new flower to the stack
  • SetStack (flower.stackparent) - updates the container so it knows an item has been added

Method 2:

  • newflower = CloneObjectAndMove (flower, player.parent) - create a clone in the room
  • DoTake (newflower, false) - have the player take it

Method 3:

  • newflower = CloneObject (flower)
  • do (newflower, "take") - as above, but a little faster

You could shorten this to: do (CloneObject (flower), "take")


This is why my stack systems are always built into the changedparent script - so that you don't need to separately deal with it in every situation where an object is moved.


Forgewright
15 Apr 2020, 17:30

Method 2 and 3 are looping copy, take, copy, take. As the clone will have the same take script. Won't they?
Anyways they freeze the game.
Method one results:
:1
flower
in the inventory pane

Is flower the object or the alias in your scripts?
Latest Game link

Also: These codes you are posting go in the Take script...Right?


mrangel
15 Apr 2020, 18:37

Ah, I assumed you would have an object 'flowers' which clones a single flower from elsewhere when the player attempts to take it; in which case the flower's own take script would be the one provided by the stack library. Having a flower which clones itself seems an odd design choice.