#Interacting with a deck object
1 messages ยท Page 1 of 1 (latest)
-- Initialization if needed
end
function onCollisionEnter(collision_info)
-- Debugging information
print("Collision detected!")
print("Collider name:", collision_info.collision_object.getName())
-- Check if the colliding object is a deck
if collision_info.collision_object.tag == "Deck" then
broadcastToAll("A custom deck is detected on top of the notecard!", {1,0,0})
else
broadcastToAll("A non-deck object is detected on top of the notecard.", {0,1,0})
end
end
function onCollisionExit(collision_info)
-- Optional: Handle when the object leaves the notecard
print("Collision ended with:", collision_info.collision_object.getName())
end```
Correctly got it to recognize a deck on the notecard, progress.
So I tried running a test from there (baby steps, like I said unfamiliar with lua- trying to learn how to do things as well as accomplish my goal) and it hit the fan again.
I figured I'd just get it to place the bottom card on the deck, to the top card of the deck. Just to prove it can manipulate cards in the deck and access them, before getting any more complex.
Here's the code, and here's the error I'm getting:
-- Initialization if needed
end
function onCollisionEnter(collision_info)
-- Debugging information
print("Collision detected!")
print("Collider name:", collision_info.collision_object.getName())
-- Check if the colliding object is a deck
local collidingObject = collision_info.collision_object
if collidingObject.tag == "Deck" then
-- Retrieve the cards from the deck
local deck = collidingObject
local deckCards = deck.getObjects()
-- Check if the deck contains any cards
if #deckCards > 0 then
-- The bottom card is typically the last card in the list
local bottomCard = deckCards[#deckCards]
if bottomCard then
local bottomCardObject = bottomCard
local deckPos = deck.getPosition()
-- Calculate the new position for the bottom card
local deckSize = deck.getScale()
local cardSize = bottomCardObject.getScale()
local newCardPos = {
x = deckPos.x,
y = deckPos.y + deckSize.y / 2 + cardSize.y / 2, -- Position above the deck
z = deckPos.z
}
-- Move the bottom card to the top of the deck
bottomCardObject.setPosition(newCardPos)
-- Notify players
broadcastToAll("Moved the bottom card to the top of the deck.", {0,1,0}) -- Green text
else
broadcastToAll("Unable to access the bottom card.", {1,0,0}) -- Red text
end
else
broadcastToAll("The deck does not contain any cards.", {1,0,0}) -- Red text
end
else
broadcastToAll("A non-deck object is detected on top of the notecard.", {0,1,0}) -- Yellow text
end
end
function onCollisionExit(collision_info)
-- Optional: Handle when the object leaves the notecard
print("Collision ended with:", collision_info.collision_object.getName())
end
The issue you are running into is that objects inside of containers (like cards in a deck) are not currently loaded. They are just stored as data (to be spawned when needed).
So you cannot get an object reference to them
Error:
Error in Script, Notecard, onCollisionEnter function:
chunk_4:(30, 16-60): attempt to call a nil value
Ah man. so what do I do?
Take a look at the code from my tool for an example solution:
getData()on the deck- manipulate the data of the deck
- destroy the deck
- respawn the manipulated deck
o.@; really?
Yep
Alright lemme go ahead and look at it, I'll be back.
Wait... how does the object tagger know what the selected objects are?
Dude your code is so much cleaner than the stuff* GPT has sent me.
Ah it's whatever's on the clipboard...
That's pretty clever
Ah man.
@solid cave I don't think GPT is gonna be any help...
I get what it does, but I don't understand the syntax. Ps. this is exactly what I wanted btw, thank you.
I'd like to use your button as a template to create something(s) very similar. Would you mind walking me through the code on how to edit it to accomplish a few tasks, so that I can build off of that knowledge to do my own stuff?
I'll try to keep the requests short and simple, so as not to be a pain in the butt or take up very much time.
In fact... it's really only 5 questions.
Feel free to post the questions
Alright while I was waiting, I did some digging and I think I understand your syntax better- your script is much cleaner than what I've seen from others.
So when you cut the fluff/failsafes, the magic happens after "if.dataContainedObjects ~= nil then"
This determines this is an object container, and it needs to be handled appropriately
So then it calls the deepTag function on (data.ContainedObjects)
and then in deepTag, it runs the "for _, obj in ipairs(ObjList) do"
and this is where the actual stuff is done to each thing in the list.
Right, so far you got it ๐
...thank you for your patience, dawg.
So I think I figured out the answer to one of my questions already. just by breaking down your stuff.
Well done
So how would I remove a card from the deck- with the ability to put it back before the end of the script runs?
Yeah especially since you're getting around the limitations by editing the data of the cards and then respawning.
I'm pretty sure it'll come up eventually... maybe they could be added to an obj. array of sorts 'removed' and that can be called on later?
I dunno what all lua is okay with or can do- or how cards are even coded for that matter
You can use takeObject() to spawn an object from a container
This spawning will take 3 frames though iirc
So you need to learn about delays then
Pretty much anything! Open your savegame in a text editor, that's very insightful
hm. so we're already fucking with a theoretical deck , then replacing the actual deck with it right? (ps can I swear here? rules were unclear)
What if we made a theoretical container and moved the theoretical cards into it, then combined the 2 later?
Before actually spawning the final product
All possible
Sweet. What are the commands/functions/whatever to achieve that?
I wouldn't recommend that as first project though ๐
getData(), destroy() and spawnObjectData()
SpawnObjectData() will spawn the container... how do I name it?
That will spawn whatever the data in the argument contains
Could be anything
The data also contains the name of the object
Beautiful. Alright... so how do I move a contained data object from container X to Y?
This is the exact format that getData gives you
Remove the data from container 1 and add it to container 2, respawn both
Keep in mind to look at this for simple operations like moving a single card
...you assign getData to container 2... and then remove it from container 1, right?
Cuz remember I don't actually need to remove the cards from the physical deck, I just need them effectively set aside until the end of the script
then at the end you do the reverse to put it back, when it's time to recombine them... before spawning the deck back onto the physical board...
That uh... accurate?
I can't follow
So like... say you're tallying a deckbuilding game score...and you get like a cursed card, that says 'blue cards are removed from your deck when scorecounting'. When tallying scores, you need them out of your deck, but only while tallying scores- that way they aren't like... deleted off the board when you run the script.
So I'm thinking, while we're manipulating data... we make a new container called "removed" and add all the removed cards to it (then deleting them from the main deck)... then we can run score keeping... and then after we have the score, move them back from removed to the main deck, delete removed, and then respawn the object
so nothings changed about the physical cards on the board.. but the score was applied correctly.
Would that work?
ps. you're right this is kinda complicated, but in theory- that'd work fine, right?
That's totally unnecessary
If your script can detect which cards to remove
It can also just skip those in the scoring?
...why not just algorythmically disregard them.
Yeah don't make it harder than needed ๐
Yeah, that's more efficient.
Yeah that makes sense. But if, for whatever reason it did need to happen that way, it would work like that? Like bouncing array data around?
I'm only asking for clarity's sake, totally just gonna do the other thing.
Yes that would be possible
Sweet, this one should be easier
can I use .length on the container object to get the number of cards in the deck?
How do I move a card in the deck a set number of cards higher or lower in it?
#tableName gives you the length of a table
beauutiful.
Deck manipulation is out of your reach for now
I mean every object has a number signifying it's order in the container, right? Shouldn't you be able to add or subtract from it to move it?
Ahhhh.
Ooof.
Alright, no problem. Almost finished. So say I have a numbered tag- like...
Cost 4 or Cost 3
how do I pull the number from that tag for things like determining if it's cost 2 or less kind of thing?
You can split strings with Lua
ChatGPT will know such basics well
But I'd recommend not having all this data in tags
Oh okay, np. So that's something I can just ask them, alright
alright last question, I promise.
Give each card an ID (store that for example in the GM Notes, they are only visible to Black) and then use that ID to look up your data from a table in Global
hmmm okay- before I go on- how would I reference said ID?
local cardId = card.getGMNotes() iirc
Ah, alright. I'll look into that, but I think splitting strings is more up my alley
Alright, final question
Or if the card is in a container:
local cardId = cardData.GM_Notes (or similar)
So like... say I ran your algorithm for editing the data, and then respawning the deck
but when I was editing the data, I split it into multiple containers- like say if I wanted to sort out the cards with a button.
How would I spawn them back in?
like if you just spawn objects will it spawn piles, or do I need to do something special?
Is there anything I should know about that?
Each instance of spawnObjectData() spawns one object
With all the properties from the data or the additional parameters from the documentation
Oh- spawnobjectdata- oh right
Aaaah that's why the previous- I see.
...hm... If I want to control positioning it'd probably be more efficient to watch my input locations...
than to spawn more things...
Alright man, thank you so much. I'm gonna go try and put what I've learned into action.
I've been trying to get this stuff out of chatGPT for over a day now and couldn't get past SEEING the friggin cards.
Cannot thank you enough. Will come back to the main forum if I run into any issues.
Sure
Might be a good idea to re-read this conversation when you have applied some of it ๐
Seriously, you've been immensely helpful. If what you've told me works out the way I think it will, I should be able to program.. just about anything I want into tabletop with the experience I already have.
You're welcome
Yeah I used to program video games back in the day- but I fuckin. haven't in a loong time. And Lua's not the language I know (although a new programming language... isn't exactly a* foreign language to someone who already knows how to program). and running it all through tabletop's GUI- adds a lot of wrinkles.
Kinda feels like you're building someone else's project, ya know? but yeah, I'm off to tinker.
Haha yeah, TTS has quite some quirks and is not super easy to get into
Make sure you're using a 3rd party code editor and not the ingame one
Yeah I'm purist, I fuckin. Go to notepad of all things.
You're a maniac
I get that alot lol