Indexing 如何处理此索引超出范围错误(行话)
您好,我正在获取:脚本错误:索引超出以下内容的范围Indexing 如何处理此索引超出范围错误(行话),indexing,lingo,macromedia,Indexing,Lingo,Macromedia,您好,我正在获取:脚本错误:索引超出以下内容的范围 sprite(spriteNumber).member = member(pBoard[cardNumber],"Cards") 这是为一个演员:我有10个演员的卡。我在一个记忆游戏中有一个20张牌的矩阵,演员必须是矩阵数的一半。但我无法克服这个错误,不管我怎么努力,它都不会消失。如果你能找出我为什么会出现这个脚本错误,请提前感谢你。干杯 放置在框架上的整个脚本如下所示: -- Settable Properties
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
——可设置的属性
属性PSPRITETOFFSET、pDisplayDelay、pGameOverFrame
属性pClickSound、pMatchSound、pNoMatchSound
属性pNumber of cards--游戏中的牌数
属性pBoard--包含一个列表,其中列出了哪些卡在哪里
属性pCard1——一对卡中单击的第一张卡
属性pCard2——两张卡中单击的第二张卡
属性pCardTimer—单击第二张卡的时间
关于getPropertyDescriptionList我
列表=[:]
--pSpriteOffset用于确定距离
--第一张牌的得分最高
--因此,如果第一张卡从通道11开始,
--偏移量为10(距离通道1 10)。
addProp列表#PSPRITE OFFSET\
[#注释:“卡精灵偏移量”\
#格式:#整数\
#默认值:0]
--pDisplayDelay是一对指针的刻度数
--卡片将保留在屏幕上供玩家使用
--在它们被移除或翻转之前查看
addProp list,#pDisplayDelay\
[#注释:“显示延迟”\
#格式:#整数\
#默认值:60\
#范围:[最小值:0,最大值:240]]
--单击精灵时,会播放什么声音?
addProp列表,#pClickSound\
[#评论:“点击声音”\
#格式:#声音\
#默认设置:“单击声音”]
--当一个精灵匹配时,会播放什么声音?
addProp列表,#pMatchSound\
[#注释:“匹配声音”\
#格式:#声音\
#默认值:“匹配声音”]
--当一个精灵不匹配时,会播放什么声音?
addProp列表,#pNoMatchSound\
[#注释:“无匹配声音”\
#格式:#字符串\
#默认值:“]
--当所有精灵都匹配时,电影应该转到哪个帧?
addProp列表,#pGameOverFrame\
[#评论:“游戏结束帧”\
#格式:#标记\
#默认值:#结束]
返回列表
终止
--洗牌以建立pBoard列表
--初始化游戏属性
从一开始就相信我
--参考“卡牌”铸造库,查看有多少张卡牌
pNumberOfCards=castLib“卡”的成员数
--用列表中的每张卡建立一个列表两次
列表=[]
重复以上步骤,i=1至P卡数
添加列表,我
添加列表,我
结束重复
--在pBoard列表中随机填写以下项目:
--以前创建的列表
pBoard=[]
在list.count>0时重复此操作
r=随机(list.count)
添加pBoard,列表[r]
删除列表,r
结束重复
--初始化游戏属性
pCard1=0
pCard2=0
终止
--当用户单击时由精灵调用
--spriteNumber参数是单击的精灵编号
在我的turnCard上,spriteNumber
--播放声音,如果有
如果是pClickSound“”,则为puppetSound 1,pClickSound
--确定卡号
cardNumber=spriteNumber-pSpriteOffset
如果pCard1=0,则--单击第一张卡
--记下这张卡
pCard1=卡号
--把它翻过来
精灵(精灵编号)。成员=成员(卡片[卡片编号],“卡片”)
否则,如果pCard2=0,则单击第二张卡
--如果是同一张卡,则忽略
如果cardNumber=pCard1,则退出
--记下这张卡
pCard2=卡号
--把它翻过来
精灵(精灵编号)。成员=成员(卡片[卡片编号],“卡片”)
--设置计时器
pCardTimer=滴答声
否则--两张牌已经翻了{6}
--如果用户很快单击,就会发生这种情况
--强迫看一眼这两张牌
返回卡(me)
--确保卡没有被点击两次
如果sprite(spriteNumber).memberNum=0,则退出
--将新卡记录为第一张卡
pCard1=卡号
--把它翻过来
精灵(精灵编号)。成员=成员(卡片[卡片编号],“卡片”)
如果结束
终止
--看两张翻过的卡片并比较它们
在我身上
如果pBoard[pCard1]=pBoard[pCard2],那么它们是匹配的
--播放声音,如果有
如果为“pMatchSound”,则为木偶声2,pMatchSound
--删除两个精灵{8}
精灵(pCard1+pSpriteOffset).memberNum=0
精灵(pCard2+pSpriteOffset).memberNum=0
--检查游戏是否结束
如果checkall匹配(我),那么
转到第PGA帧第二帧
如果结束
否则,就没有对手了
--播放声音,如果有
如果是pNoMatchSound“”,则为木偶声2,pNoMatchSound
--把两张牌都翻回去{7}
精灵(pCard1+pSpriteOffset)。成员=成员(“卡片背面”)
精灵(pCard2+pSpriteOffset)。成员=成员(“卡片背面”)
如果结束
--重置游戏属性
pCard1=0
pCard2=0
终止
在exitFrame me上
如果pCard1 0和pCard2 0,则--转动两张卡
如果滴答声>pCardTimer+pDisplayDelay,则--time已过期
--检查卡片,看是否有匹配
返回卡(me)
如果结束
如果结束
--在框架上循环
_movie.go(_movie.frame)
终止
--看看比赛是否结束了
在支票上,所有的都与我相符
--遍历所有卡片
重复以上步骤,i=1至P卡数
--确定卡的精灵
spriteNumber=i+pSpriteOffset
--如果它仍然是一张牌,那么游戏还没有结束
如果sprite(i).memberNum为0,则返回FALSE
结束重复
--所有的牌都丢了,游戏结束
返回真值
终止
这是放置在矩阵中精灵上的脚本:
在我身上
--只需告诉框架脚本该精灵已被单击
sendSprite(0,#turnCard,me.spriteNum)
终止
我只是
-- 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
-- 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