0

好的,所以我正在为迪士尼现已关闭的游戏 Toontown Online 制作服务器,但我在添加此代码后遇到了问题。游戏需要这部分,它对游戏至关重要,没有它,游戏将不发送客户端,“AvatarChooser.enter”,玩家将无法创建他们的角色!如果需要,我会放出更多的代码,但现在是这样。

class DistributedDistrict(DistributedObject):
__module__ = __name__
notify = directNotify.newCategory('DistributedDistrict')
neverDisable = 1

def __init__(self, cr):
    print 'DistributedDistrict: BlankTest Canvas is now Online..'
    DistributedObject.__init__(self, cr)
    self.name = 'BlankTest Canvas'
    self.available = 0
    self.avatarCount = 0
    self.newAvatarCount = 0

def announceGenerate(self):
    DistributedObject.announceGenerate(self)
    self.cr.activeDistrictMap[self.doId] = self
    messenger.send('shardInfoUpdated')

def delete(self):
    if base.cr.distributedDistrict is self:
        base.cr.distributedDistrict = None
    if self.cr.activeDistrictMap.has_key(self.doId):
        del self.cr.activeDistrictMap[self.doId]
    DistributedObject.delete(self)
    messenger.send('shardInfoUpdated')
    return

def setAvailable(self, available):
    self.available = available
    messenger.send('shardInfoUpdated')

def setName(self, name):
    self.name = name
    messenger.send('shardInfoUpdated')

simbase = DistributedDistrict()
#run() # Initialize the Panda3D API.

我收到此错误:

TypeError: __ init __() 正好需要 2 个参数(1 个给定)

任何帮助将不胜感激!

错误发生在:

simbase = DistributedDistrict()
#run() # Initialize the Panda3D API.
4

3 回答 3

1

“当我将其设置为 5 时,它起作用了”

您不应该将其设置为5. 该cr参数需要一个ClientRepository参数。

于 2013-12-29T15:23:50.080 回答
0

在谈论分布式对象(在本例中为 DistributedDistrict)时,您需要签入 DistributedClass 文件以查看它实际占用的字段,在此您会发现它看起来像这样(如果您想自己查看,请查看 otp .dc 在您的卡通城目录中)

dclass DistributedDistrict : DistributedObject {
    setName(string) required broadcast ram;
    setAvailable(uint8) required broadcast ram;

在这里,您可以看到您在代码中呈现的 2 个字段,现在虽然您可以只提供ClientRepository此代码,但您还需要查看它DistributedObject是否具有 AI 或 UD (UberDOG) 表示。您可以通过(再次)查看 otp.dc 来解决这个问题

from otp.distributed import DistributedDistrict/AI/UD

在这里您可以看到它DistributedDistrict实际上DistributedObject是由 AI 服务器生成的。这意味着服务器是该对象的所有者,并且除了服务器之外没有人可以设置值 setName 和 setAvailable。为了让它正确运行,您需要编写一些东西来接收普通DistributedDistrict.py文件发送的更新,必须调用这个新的 AI 文件,DistributedDistrictAI.py并且必须在 AIRepository 中将其创建为新的 DistributedObject。它也是 UberDOG 的事实也意味着您需要编写 DistributedObject 的 DistributedDistrictUD.py 表示,然后应该在您的 UDRepository 上创建它。

希望这会为您指明正确的方向,祝您的项目好运。

于 2014-04-25T10:53:24.060 回答
0

请注意此行中的参数数量:

simbase = DistributedDistrict()

现在,查看构造函数DistributedDistrict

def __init__(self, cr):

Theself隐含在构造函数中,但您忘记了cr参数。

要解决此问题,您需要:

simbase = DistributedDistrict(some_value) # wasn't sure what the value of cr would be
于 2013-11-30T04:48:27.013 回答