Tabletop Simulator

Tabletop Simulator

Card Naming Tool
 此主题已被置顶,因此可能具有重要性
Hiram Abiff  [开发者] 2020 年 6 月 13 日 上午 6:45
- General Discussion
As the title says, this is a place to discuss this mod. Please use this section to ask questions or talk about scripting, ect. Because comments that are left on the workshop page have character limitations, this general discussion will allow me to respond in greater detail.
最后由 Hiram Abiff 编辑于; 2020 年 6 月 13 日 上午 6:46
< >
正在显示第 1 - 4 条,共 4 条留言
Hiram Abiff  [开发者] 2020 年 6 月 13 日 上午 8:03 
引用自 tream2001
Hey Hiram Abiff, I really like your Card Naming Tool. I have been trying to get into scripting for Tabletop Simulator recently which has been a bit of a challenge as I am completely new to coding in LUA as I have only ever used Java before. Anyways, I was looking through your code to try and learn about LUA through example and the one thing that has me confused is the purpose of the if statement checking "nameKey == numberOfCards-1" within the "takeAndRename()" function. I understand that the code within the if statement only runs if the current card being renamed is the second to last card. However, the code within the statement seems identical except with "newCard" being replaced with "cardRef" and the "onObjectSpawn(obj)" function possibly being used despite the lack of anything being spawned as far as I can tell. Any clarification on the statement's purpose would be appreciated.

After drawing the second from the last card using deck.takeObject, the decks GUID reference no longer exists because the deck itself doesn't exist as an object on the table. Therefore, I had the script watch for when the last card is spawned, and then it uses onObjectSpawn to acquire the cards GUID. The cardRef is then used under "if deck == nil" so as to rename and move the last card.

newCard is a reference to a card pulled from the deck using takeObject.
cardRef is a reference to the last card, created by onObjectSpawn.

The two references need to exist at the same time, because the reference for the final card is created at the same time the second to last card is still being manipulated with the old reference. If you were to replace the cardRef with newCard, the last card will not be moved because the card before it is still using the newCard reference.

I hope this answers your question and doesn't go to further confuse you. If you have any additional questions, or still don't understand what I described above, feel free to let me know. Good Luck.

~Hiram
最后由 Hiram Abiff 编辑于; 2020 年 6 月 13 日 上午 8:09
Tream 2020 年 6 月 13 日 下午 7:04 
I suspected that it had something to do about copying over the GUID, but the part that had me stumped for the longest time was when the object was being spawned. I didn't realize that, when the deck has one card, it deletes itself and spawns in the last card with the same GUID like you said. Thank you so much for the help!
Sfendili 2020 年 11 月 23 日 下午 2:33 
If names contain commas and forward slashes do we use backslash before them too? Or are these characters intolerable to the script?
Hiram Abiff  [开发者] 2020 年 11 月 23 日 下午 11:30 
引用自 Sfendili
If names contain commas and forward slashes do we use backslash before them too? Or are these characters intolerable to the script?

Correct; if you want to use a backslash, just use a backslash before it, i.e "double backslash".

'The chef\'s cake scored an 8\\10.'
< >
正在显示第 1 - 4 条,共 4 条留言
每页显示数: 1530 50