2017-12-10 7 views
-2

現在ゲーム用に作っているluaスクリプトのヘルプが必要です。エラーのためにモンスターが生成されない問題を修正しました

addhook("ms100", "MONSTERms100") 
function MONSTERms100() 
    t = t + 1 
    if t % 100 == 0 then 
     while #MONSTERS < CONFIG.MAXMONSTERS do 
      local rand, spawnNo, mapName 
      while true do 
       rand = math.random(#CONFIG.MONSTERS) 
       mapName = CONFIG.MONSTERS[rand].spawn[map'name'] and map'name' or CONFIG.DEFAULTMAP 
       spawnNo = math.random(#CONFIG.MONSTERS[rand].spawn[mapName]) 
       if math.random(0, 100) < CONFIG.MONSTERS[rand].spawnchance[mapName][spawnNo] then 
        break 
       end 

LUAのERROR:SYS/LUA /ワッフル/ monsters.lua:411:フィールドの長さを取得しようとすると '?' (ゼロ値) - > sys/lua/waffle/monsters.lua:411:in function

複数回チェックしても解決策が見つかりませんでした。以前はこのエラーは起こりませんでしたが、このファイルでは何も編集しませんでした。私はゲームを更新したときに始まりました。だから私がしようとしているのは、産卵するモンスターをコントロールすることですが、今はまったく産卵していません。これは私の最初の時間です。私が馬鹿だからこのことを解決しようとしてくれてありがとう。

答えて

0

エラーメッセージ

sys/lua/waffle/monsters.lua:411: attempt to get length of field '?' (a nil value) -> sys/lua/waffle/monsters.lua:411: in function

length operator

であるあなたは、ファイルmonsters.luaラインに411

while #MONSTERS < CONFIG.MAXMONSTERS do 

#nil値の長さを取得しようとしていることを示しています

からLua Reference Manual 5.3 - 3.4.7 The Length Operator

The length operator applied on a table returns a border in that table. A border in a table t is any natural number that satisfies the following condition:

(border == 0 or t[border] ~= nil) and t[border + 1] == nil In words, a border is any (natural) index in a table where a non-nil value is followed by a nil value (or zero, when index 1 is nil).

A table with exactly one border is called a sequence. For instance, the table {10, 20, 30, 40, 50} is a sequence, as it has only one border (5). The table {10, 20, 30, nil, 50} has two borders (3 and 5), and therefore it is not a sequence. The table {nil, 20, 30, nil, nil, 60, nil} has three borders (0, 3, and 6), so it is not a sequence, too. The table {} is a sequence with border 0. Note that non-natural keys do not interfere with whether a table is a sequence.

When t is a sequence, #t returns its only border, which corresponds to the intuitive notion of the length of the sequence. When t is not a sequence, #t can return any of its borders. (The exact one depends on details of the internal representation of the table, which in turn can depend on how the table was populated and the memory addresses of its non-numeric keys.)

The computation of the length of a table has a guaranteed worst time of O(log n), where n is the largest natural key in the table.

簡単に言えば、MONSTERSはまだ定義されていません。だからあなたはその要素の数を得ることができません。あなたがCONFIG.MONSTERSを使用しているので、私は#CONFIG.MONSTERSを使用して問題を解決するはずです。それがあなたが実際に使いたいテーブルです。しかし、あなたのコードの残りの部分を知らないと、私は推測できません。

関連する問題