Is it possible to send a time-delayed message with parameters?
Posted: Mon Nov 30, 2020 7:25 pm
Pretty much as the title says. I'm making a mobile game for fun where the player plays as a spaceship and needs to pass all sorts of challenges (the user controls the player using the accelerometer) and the last "boss" level is going through an "asteroid belt" and avoiding getting hit. The asteroids are spawned at the top of the screen and then move down using "move". I've got it all figured out other than when the asteroids reach the bottom of the screen, I'd like to delete them rather then them piling up at the bottom and using the processing power of the phone, I'd like to delete the asteroids. The problem is, the only way I could think of doing this is to send a custom event (I'm sorry if this isn't the correct terminology, English is my second language, code below for clarification.) with a time delay, the issue is, I can't seem to find a command that allowed both sending parameters (which I need due to the way the code is written) and a time delay, any ideas?
code:
full code if anyone is interested:
Thank you for reading!
code:
Code: Select all
on MoveAst
put (item two of loc of _gAsteroidID + 658) into _tYcoord
move _gAsteroidID to (item one of loc of _gAsteroidID) , _tYcoord in 7 sec without waiting
dispatch EndOfLife to _gAsteroidID in 7 sec {I'd like to add parameters here}
end MoveAst
on EndOfLife pAstID pAstNum
if the bottom of pAstID is 645
then
delete variable _gAstList[pAstID]
delete pAstID
else
send EndOfLife to _gAsteroidID in one tick with pAstID , pAstNum
end if
end EndOfLife
Code: Select all
--Vars--
global _gAsteroidBaseName
global _gAsteroidNumber
global _gNameingState
global _gCurrentAstroidName
global _gAsteroidID
global _gIconID
global _gAstList
--methods--
on CreateAsteroid
put "Asteroid_" into _gAsteroidBaseName --setsThe base name for each astroid made ["Asteroid_XX"]
put AsteroidNameMaker() into _gCurrentAstroidName --calls the name making function in a var
create invisible graphic _gCurrentAstroidName --creats new graphic w/ the name stored in the var
put the long ID of graphic _gCurrentAstroidName into _gAsteroidID --stores the ID of the newly made asteroid
put _gAsteroidID into _gAstList[_gAsteroidNumber]
add 1 to _gAsteroidNumber --adds 1 to the var for the next asteroid made
end CreateAsteroid
on SetAstPropoties
put the long ID of ChooseIcon() into _gIconID --calls the icon chooser function and stores it in a var
set the backgroundPattern of _gAsteroidID to the id of _gIconID --changes the icon of the asteroid
set the opaque of _gAsteroidID to true
set the colorOverlay of _gAsteroidID to false
set the lineSize of _gAsteroidID to 0
set the lockloc of _gAsteroidID to true
set the width of _gAsteroidID to 100
set the height of _gAsteroidID to 100
set the left of _gAsteroidID to (random(220))
set the bottom of _gAsteroidID to 0
set the visible of _gAsteroidID to true
end SetAstPropoties
on MoveAst
put (item two of loc of _gAsteroidID + 658) into _tYcoord
move _gAsteroidID to (item one of loc of _gAsteroidID) , _tYcoord in 7 sec without waiting
dispatch EndOfLife to _gAsteroidID in 7 sec _gAsteroidID , (_gAsteroidNumber - 1)
end MoveAst
on CheckCollisons
repeat for each element _tLine in _gAstList
if intersect (_gAsteroidID , _tLine , "pixels") and _gAsteroidID <> _tLine
then
put "yes" into _tToDel
end if
end repeat
if _tToDel is "yes"
then
delete variable _gAstList[(_gAsteroidNumber - 1)]
delete _gAsteroidID
else
MoveAst
end if
end CheckCollisons
on EndOfLife pAstID pAstNum
if the bottom of pAstID is 645
then
delete variable _gAstList[pAstID]
delete pAstID
else
send EndOfLife to _gAsteroidID in one tick with pAstID , pAstNum
end if
end EndOfLife
--functions--
function AsteroidNameMaker
if _gNameingState is not "passedIf" --checks if this the first time an asteriod is made
then
put 0 into _gAsteroidNumber --resets the var
put "passedIf" into _gNameingState
end if
return (_gAsteroidBaseName & _gAsteroidNumber) --returns the name
end AsteroidNameMaker
function ChooseIcon
put the long ID of img "asteroidOne" into _tImage[1]
put the long ID of img "asteroidTwo" into _tImage[2]
return _tImage[random(2)] --chosses one of the (2) images
end ChooseIcon