Что делать с этой ошибкой индекса вне диапазона (LINGO)

Здравствуйте, я получаю: Ошибка скрипта: Индекс вне диапазона для следующих

       sprite(spriteNumber).member = member(pBoard[cardNumber],"Cards")

Это для разыгрыша карт: карт, в которых у меня есть 10 участников. У меня есть матрица из 20 карт в игре с памятью, и члены актерского состава должны вдвое уменьшить число матриц. Но я не могу преодолеть эту ошибку, которая не исчезнет, ​​как бы я ни старался. Заранее благодарю, если вы можете понять, почему я получаю эту ошибку сценария. Приветствия.

Весь сценарий, который помещен в рамку, гласит:

     -- Settable Properties
     property pSpriteOffset, pDisplayDelay, pGameOverFrame
     property pClickSound, pMatchSound, pNoMatchSound
     property pNumberOfCards -- number of cards in the game
     property pBoard -- holds a list of what cards are where
     property pCard1 -- the first card in a pair clicked on
     property pCard2 -- the second card in a pair clicked on
     property pCardTimer -- the time that the second card was clicked


     on getPropertyDescriptionList me
       list = [:]

  -- pSpriteOffset is used to determine how far from
  -- the top of the Score the first card is
  -- so, if the first card starts in channel 11,
  -- the offset would be 10 (10 away from channel 1).
  addProp list, #pSpriteOffset,\
    [#comment: "Card Sprite Offset",\
     #format: #integer,\
     #default: 0]

  -- pDisplayDelay is how many ticks the pair of
  -- cards will be kept on the screen for the player
  -- to see before they are removed or turned back over
  addProp list, #pDisplayDelay, \
    [#comment: "Display Delay",\
     #format: #integer,\
     #default: 60,\
     #range: [#min: 0, #max: 240]]

  -- when a sprite is clicked, what sound is played?
  addProp list, #pClickSound,\
    [#comment: "Click Sound",\
     #format: #sound,\
     #default: "click sound"]

  -- when a sprite is matched, what sound is played?
  addProp list, #pMatchSound,\
    [#comment: "Match Sound",\
     #format: #sound,\
     #default: "match sound"]

  -- when a sprite is not matched, what sound is played?
  addProp list, #pNoMatchSound,\
    [#comment: "No Match Sound",\
     #format: #string,\
     #default: ""]


  -- when all sprites are matched, which frame should the movie go to?
  addProp list, #pGameOverFrame,\
    [#comment: "Game Over Frame",\
     #format: #marker,\
     #default: #end]
  return list
     end


     -- shuffles the cards to build the pBoard list
     -- initializes the game properties
     on beginSprite me


  -- refers to the "Cards" cast library to see how many cards there are
  pNumberOfCards = the number of members of castLib "Cards"


  -- build a list with each card in the list twice
  list = []
  repeat with i = 1 to pNumberOfCards
    add list, i
    add list, i
  end repeat


  -- fill the pBoard list up randomly with items from
  -- the previously created list
  pBoard = []
  repeat while list.count > 0
    r = random(list.count)
    add pBoard, list[r]
    deleteAt list, r
  end repeat


  -- initialize the game properties
  pCard1 = 0
  pCard2 = 0
     end


     -- called by the sprites when the user clicks
     -- the spriteNumber parameter is the sprite number clicked
     on turnCard me, spriteNumber
  -- play sound, if there is one
  if pClickSound <> "" then puppetSound 1, pClickSound


  -- determine the card number
  cardNumber = spriteNumber - pSpriteOffset


  if pCard1 = 0 then -- first card clicked
    -- record this card
    pCard1 = cardNumber
    -- turn it over
    sprite(spriteNumber).member = member(pBoard[cardNumber],"Cards")


  else if pCard2 = 0 then -- second card clicked
    -- ignore if it is the same card
    if cardNumber = pCard1 then exit
    -- record this card
    pCard2 = cardNumber
    -- turn it over
    sprite(spriteNumber).member = member(pBoard[cardNumber],"Cards")
    -- set the timer
    pCardTimer = the ticks


  else -- two cards are already turned over{6}
    -- this happens if the user clicks very quickly
    -- force a look at the two cards
    returnCards(me)
    -- make sure the card was not clicked on twice
    if sprite(spriteNumber).memberNum = 0 then exit
    -- record new card as the first card
    pCard1 = cardNumber
    -- turn it over
    sprite(spriteNumber).member = member(pBoard[cardNumber],"Cards")
  end if
     end


     -- looks at the two cards turned over and compares them
     on returnCards me
  if pBoard[pCard1] = pBoard[pCard2] then -- they are a match
    -- play sound, if there is one
    if pMatchSound <> "" then puppetSound 2, pMatchSound
    -- remove both sprites{8}
    sprite(pCard1+pSpriteOffset).memberNum = 0
    sprite(pCard2+pSpriteOffset).memberNum = 0
    -- check for game over
    if checkAllMatched(me) then
      go to frame pGameOverFrame
    end if
  else -- no match
    -- play sound, if there is one
    if pNoMatchSound <> "" then puppetSound 2, pNoMatchSound
    -- turn both cards back{7}
    sprite(pCard1+pSpriteOffset).member = member("Card Back")
    sprite(pCard2+pSpriteOffset).member = member("Card Back")
  end if


  -- reset the game properties
  pCard1 = 0
  pCard2 = 0
     end


     on exitFrame me
  if pCard1 <> 0 and pCard2 <> 0 then -- two cards are turned
    if the ticks > pCardTimer + pDisplayDelay then -- time has expired
      -- check the cards to see if there is a match
      returnCards(me)
    end if
  end if



  -- loop on the frame
     _movie.go(_movie.frame)
       end


     -- check to see if the game is over
     on checkAllMatched me
  -- loop through all cards
  repeat with i = 1 to pNumberOfCards
    -- determine the card's sprite
    spriteNumber = i + pSpriteOffset
    -- if it is still a card, then the game is not over
    if sprite(i).memberNum <> 0 then return FALSE
  end repeat


  -- all cards missing, so game over
  return TRUE
     end

     and this is the script that is placed on the sprite in the matrix:

     on mouseUp me
  -- simply tell the frame script that this sprite was clicked
  sendSprite(0,#turnCard,me.spriteNum)
     end

1 ответ

Что ж, я просто даю всем, кто читает, знать, что наконец-то решил свою собственную проблему, после долгих раздумий и просмотра кода снова и снова.

Вот что я сделал:

Здесь я заметил, что есть код, чтобы добавить список дважды

-- build a list with each card in the list twice
  list = []
  repeat with i = 1 to pNumberOfCards
    add list, i
    add list, i
  end repeat

поэтому я подумал, что я получаю только одну часть этого списка в моей матрице, и у меня наконец появилась ясная идея, что где-то в этом коде есть еще один список для добавления. Поэтому я посмотрел внимательно и, наконец, предположил, что:

 -- fill the pBoard list up randomly with items from
  -- the previously created list
  pBoard = []
  repeat while list.count > 0
    r = random(list.count)
    add pBoard, list[r]
    deleteAt list, r
  end repeat

вышеупомянутое имеет

добавить pBoard, список [r]

в коде один раз, так что, возможно, мне нужно добавить еще

Поэтому я закончил с:

-- fill the pBoard list up randomly with items from
  -- the previously created list
  pBoard = []
  repeat while list.count > 0
    r = random(list.count)
    add pBoard, list[r]
     add pBoard, list[r]
    deleteAt list, r
  end repeat

которая решила мою ошибку и теперь игра работает. Какое облегчение!

Другие вопросы по тегам