#Duplicating objects instead of drawing

1 messages · Page 1 of 1 (latest)

high citrus
#

Let's discuss this here

fast raft
#

Alright

high citrus
#

Basically, there's a fair few caveats to what you want to do, most of which involve anticipating how users may try to remove an object from the container

#

In your use-case, you want to copy a single random object?

fast raft
#

Yeah, just like a single random object from a specific deck if possible.

high citrus
#

and how do you want your users to cause this to happen?

fast raft
#

I'm not 100% sure. I'd like to have an object they can "use" to activate this script, possibly multiple times, essentially removing the objecting and putting the cards from the specified decks directly into their hand. However, I'm not sure if that's something that's easily doable.

high citrus
#

a button to click on the table?

#

and the duplicated object goes into their hand?

fast raft
#

A button to click would work.

high citrus
#

so first you need to make a button, drop an object roughly where you want the button to be, then save and load your game

#

right-click the dropped object and go to Scripting -> Scripting Editor

#

this code will create a button on that object, paste into the window and hit save & play (remove anything else there):

function onLoad()
  self.createButton({
    function_owner = self,
    click_function = "clickFunction",
    position = Vector(0, 1, 0),
    rotation = Vector(0, 0, 0),
    label = "Draw",
    width = 1000,
    height = 500,
  })
end

function clickFunction(obj, player_color, alt_click)
  print(player_color.." clicked me!")
end
#

you should see a button, and then press it to get a message in your Game chat.

fast raft
#

I see!

high citrus
#

so that's step 1, getting a button

#

step 2 is to get your container - is it a deck or a bag?

fast raft
#

I am not 100% sure which it will be. Would it be alright if we covered how to do it for each so I may do it both ways in the future?

high citrus
#

decks are more of an issue than bags because they get destroyed when reduced down to 1 card

#

usually it is best to control where a deck remains, so you can find it by position

#

for bags, you can just use its guid in most cases to find it. you can find an object's guid by right-clicking an object and going to Scrpiting -> GUID

#

it'll be a six digit hexidecimal string e.g. "abc123"

fast raft
#

So you're saying that even if its all cards, it'd be better just to store them in a bag?

high citrus
#

no

#

i'm saying it's easier for bags than it is for decks, but decks offer so many other useful features

#

nowadays the best method is probably tagging with some extra

#

if you pull all your cards out, and tag each one through the right-click menu with a tag e.g. "Card"

#

and then add this script to your Global scripting window (scripting - > scripting editor -> Global):

#
function onObjectEnterContainer(enter_object)
  if (container.type == "Card" or container.type == "Deck") and enter_object.hasTag("Card") then
    container.addTag("Card")
  end
end
#

this will ensure your deck will always have the "Card" tag when re-formed

#

this is useful because to find an object with a tag is quite easy

#

now I'm off to sleep now but someone else may help you pick this up

fast raft
#

Thank you.

fast raft
#

I have the button, but we never got to how to get to drawing things

#

I'm going to head out, I'll look for through the api to try to find it myself, when I get back. I'll let you know if I find it, but if not, the help would still be appreciated :)

fast raft
#

I see how to simply deal or remove an item, but doing it in a way that gives a duplicate of the item the player seems more difficult than expected.