Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my counter dosn't count in a right way

Status
Not open for further replies.

nicoka

Instructor
Feb 28, 2005
1
NL
some object intersects 7 other objects and then the blend is set to 30 and the counter must increase with 1. But in this case the counter dosn't count in a right way, it is falling down to 1 again after one or two intersects. Wy is that, what is wrong
(sorry for my english, i am dutch)

property pSprite, snelheid, punten, raak, timer

on beginsprite me
pSprite=sprite(me.spriteNum)
punten=0
put punten into field "puntentelling"
snelheid=4
end



end

on prepareframe me
-- prepareframe; nadat het frame verlaten is en voordat
-- het volgende frame wordt binnengegaan
controleerinput(me)
controleerbotsing(me)
tijdscontrole(me)


end

on tijdscontrole me
put the timer/60 into field "verstrekentijd"
end

on controleerinput me
if keyPressed(126) then -- naar bovenpijl
pSprite.locV=pSprite.locV-snelheid
else if keyPressed(125) then --naar beneden pijl
pSprite.locv=pSprite.locv+snelheid
end if
if keyPressed(123) then -- naar links
pSprite.loch=pSprite.loch-snelheid
else if keyPressed(124) then --naar rechts
pSprite.loch=pSprite.loch+snelheid
end if
end

on controleerbotsing me
repeat with i = 9 to 15 --lus door sprite 9 tot 14
if pSprite.intersects(sprite(i)) and raak<>i and sprite(i).blend<>30 then
--geeft actie bij raken van de opstakels
sprite(i).blend=30
punten=punten+1
put punten into field "puntentelling"

raak=i
exit repeat
end if
end repeat

end
 
It looks like your script is attached to multiple sprites. Because your "punten" is set as a property of each sprite, each sprite has different "punten" value - this will result in the field "puntentelling" displaying unpredictable numbers.

One way to solve this is to re-write your script as a score script with "punten" as a global variable.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top