#Duplicating objects instead of drawing
1 messages · Page 1 of 1 (latest)
Alright
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?
Yeah, just like a single random object from a specific deck if possible.
and how do you want your users to cause this to happen?
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.
A button to click would work.
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.
I see!
so that's step 1, getting a button
step 2 is to get your container - is it a deck or a bag?
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?
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"
So you're saying that even if its all cards, it'd be better just to store them in a bag?
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
Thank you.
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 :)
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.