gpt4 book ai didi

lua - 在lua中将单个 Sprite 存储在多个表中

转载 作者:行者123 更新时间:2023-12-04 19:36:24 25 4
gpt4 key购买 nike

由于我缺乏理解和知识,我认为这会奏效,但事实并非如此。

我有 4 个 Sprite ,我希望将它们存储在 4 个不同的表中。我在想 Sprite 实际上会在 table 上,我可以命名它等等......但它似乎指向 Sprite 和我喜欢更改名称的任何事情,实际上更改了 Sprite 上的名称,因此名称在所有其他表。

spriteOne[1] = redFlower
spriteOne[2] = purpleSpiderWeb
spriteOne[3] = brownSpider
spriteOne[4] = greenSnake
spriteOne[1].name = "1"
spriteOne[2].name = "1"
spriteOne[3].name = "1"
spriteOne[4].name = "1"

print("sprite One:" .. spriteOne[1].name) --prints 1

spriteTwo[1] = redFlower
spriteTwo[2] = purpleSpiderWeb
spriteTwo[3] = brownSpider
spriteTwo[4] = greenSnake
spriteTwo[1].name = "2"
spriteTwo[2].name = "2"
spriteTwo[3].name = "2"
spriteTwo[4].name = "2"

print("sprite One:" .. spriteOne[1].name) --prints 2

spriteThree[1] = redFlower
spriteThree[2] = purpleSpiderWeb
spriteThree[3] = brownSpider
spriteThree[4] = greenSnake
spriteThree[1].name = "3"
spriteThree[2].name = "3"
spriteThree[3].name = "3"
spriteThree[4].name = "3"

print("sprite One:" .. spriteOne[1].name) --prints 3

spriteFour[1] = redFlower
spriteFour[2] = purpleSpiderWeb
spriteFour[3] = brownSpider
spriteFour[4] = greenSnake
spriteFour[1].name = "4"
spriteFour[2].name = "4"
spriteFour[3].name = "4"
spriteFour[4].name = "4"

print("sprite One:" .. spriteOne[1].name) --prints 4

所以现在假设我需要 16 个单独的 Sprite 并且不能通过只有 4 个来捷径。

最佳答案

以这种方式尝试,这将得到你想要的。

spriteOne[1] = {}
spriteOne[2] = {}
spriteOne[3] = {}
spriteOne[4] = {}
spriteOne[1].img = redFlower
spriteOne[2].img = purpleSpiderWeb
spriteOne[3].img = brownSpider
spriteOne[4].img = greenSnake
spriteOne[1].name = "1"
spriteOne[2].name = "1"
spriteOne[3].name = "1"
spriteOne[4].name = "1"

print("sprite One:" .. spriteOne[1].name)

spriteTwo[1] = {}
spriteTwo[2] = {}
spriteTwo[3] = {}
spriteTwo[4] = {}
spriteTwo[1].img = redFlower
spriteTwo[2].img = purpleSpiderWeb
spriteTwo[3].img = brownSpider
spriteTwo[4].img = greenSnake
spriteTwo[1].name = "2"
spriteTwo[2].name = "2"
spriteTwo[3].name = "2"
spriteTwo[4].name = "2"

print("sprite One:" .. spriteOne[1].name)

关于lua - 在lua中将单个 Sprite 存储在多个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60874843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com