Basic Arcade Demo Help

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

Post Reply
jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Basic Arcade Demo Help

Post by jpatten » Sun May 27, 2012 2:01 am

Hi All...

I've attached a little demo stack I'd like to use for part of a presentation of what can be done with AE and LiveCode. It is piecemealed from examples in this forum and things I have dug up from the LiveCode discussion archives. It is just a rough draft and not complete.

I have a couple questions, related to AE. Using the new AEStartListeningForCollisions, it seems when ever two targets overlap each other (I'm moving targets along the points of a path) and they are hit by the "bullet," LiveCode will throw up the stack "animationEngine" error with the password protect script editor dialog. It only happens when two targets overlap? What can I do to solve this?

Second question, almost every time, one of my targets will be on a layer that can not be hit by the bullet. If I stop the animation, change the layer of the target by one layer, and shoot it again, it hits the target. I tried changing layers of my targets on the fly, but that did not seem to work. It only happens with one target. (There are a total of 11 targets.) What can I do to get this from happening? Could be frustrating to shoot at a target that the "bullets" just go right through :)

Thanks for any suggestions!
Attachments
ArcadeDemoPresentation.livecode.zip
Demo of AE Capabilites for presentation
(216.43 KiB) Downloaded 492 times

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Sun May 27, 2012 6:38 am

Hey John,

which version of AE are you using?

All the best,

Malte

jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Re: Basic Arcade Demo Help

Post by jpatten » Sun May 27, 2012 5:32 pm

Hi Malte...

I'm using the following:

LiveCode 5.5.0

OSX 10.7.4

Animation Engine 5.0.2

Where you not able to duplicate the same results using my example?

Thanks!

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Sun May 27, 2012 8:01 pm

Hey John,

I do get errors, but not AE ones :)

Quick glance at the script seems to suggest that you do something on objects that no longer appear to exist. I would suggest to wrap the stuff you are doing in aeCollision into an if then statement.

if there is a pObject then
--do stuff

I am sorry I can not be more helpful here. What you could do is wrap the stuff you are doing into a try catch structure

try
-- the stuff in your start stop button
catch theErr
put theErr
end try

and post the result here.

All the best,

Malte

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Sun May 27, 2012 8:05 pm

John,

please excuse my dumbness...

pObjects holds a LIST of objects delimited by carriage return.

So the statement

if the visible of pBojects is true in your script

will throw an error, because there is more than one object in the list if they overlap.

Instead try

repeat for each line theObject in pObjects
if the visible of theObject then
-- rest of handler
end if
end repeat

Hope that helps,

Malte

jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Re: Basic Arcade Demo Help

Post by jpatten » Sun May 27, 2012 11:15 pm

Hi Malte...

I worked out one issue I was having with the layers of my targets. It seems there was always target that would either be a layer 1 or 13 that would not react to being hit with a "bullet." If I changed this single target to one layer higher, 14, it would then allow the collision to take place between bullet and target. I just had the resulting collisions change the pObjects layer when struck to layer 13. Doing so mixed up all the other layers automatically and then I did not have the layer issue.

I'm still having the AE error window pop up on me when shooting at targets and hitting targets that are over one another. I tried using the try/catch process to see what was going on but it immediately brings up the AE password protected script page. I attached an image of the error message below.

Thank you!
Attachments
Screen-Shot-2012-05-27-at-3.05.gif
Error image

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Mon May 28, 2012 1:03 pm

Hi John,

I would love to be able to reproduce this...

The cause seems to be either a check against a non existing object, or an invalid object reference. However, I have not been able to reproduce this over here yet, though I must admit I have not dug too deeply into your stack as yet. If you could provide a simple recipe to bring the ae error dialogue up, this would be much appreciated.

All the best,

Malte

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Mon May 28, 2012 1:10 pm

BTW, Did you change the script of your aeCollision handler to something like this?


on aeCollision pObjects
repeat for each line theObject in pObjects
if the visible of theObject is true then
put theObject & cr after fld "collisions"
hide theObject
end if
end repeat
pass aeCollision
end aeCollision

Also, you might want to add an empty

on mouseDoubleUp

handler at card level, to avoid the animation to go jerky when you hit the fire button often.

All the best,

malte

jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Re: Basic Arcade Demo Help

Post by jpatten » Mon May 28, 2012 4:44 pm

Hi Malte...

I did make the change as you suggested. I'm still getting the error to pop up though. Sometimes it does not occur, sometimes it does. This leads me to the idea that it's related to some specific action. Not sure? Maybe when the targets move over the shooter? Maybe when the targets aree hit when they are overlapping one another? Here's a short screen capture of it happening, http://youtu.be/XNwLnwzyUH8 . (I left the audio in to you could hear the mouse clicks.)

Thanks!

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Mon May 28, 2012 7:15 pm

Hi John,

thanks for your patience. I am able to reproduce the error throwing now. Somehow script debug mode was turned off in my environment, which did cause the error not to be thrown. Once I turned it on, I see what you see. Am still a little puzzled as to the place it jumps to with the error. Need to dig a little into this.

Will keep you posted. Malte

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Basic Arcade Demo Help

Post by malte » Mon May 28, 2012 8:15 pm

Ok.

Explaining this will take a while, so please bear with me.. :-)

First of all, I *think* ae is correct to error out, however the way it does it is not ideal, at least not when script debug mode is true.

What is happening. You create bullents, and each of them has the same name. You then set up a collision listener for it. Inbetween you create new bullets with the same name and set up a listener for them, however the check will run for the first bullet created (the one with the lowest layer to be more precise), until it is moved off screen and there destroyed. Now the next bullet is being tested again, however at no point in your script all bullets are being tested. That explains why sometimes colliding objects do not get reported correctly.

Also it causes that you destroy an object, while it is being destroyed and that causes the error being thrown. The object being tested against is destroyed while it is being tested for collisions.

I hope what I am writing here makes any sense to you. Long story short...

I might change AE internally to check against the long ID instead of the long name (which would be a good idea anyway) and I will then be able to check if the object being tested still exists within the tests. This will not be before 5.1 though.

Your strategy should be, to give each bullet a unique name. Also, please switch moving the bullet from movelinear to aeMoveTo. This will be a lot less CPU consuming.

If you send me an updated version of your stack, I'll gladly take a look again during the course of this week.

Hope that helps,

Malte

jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Re: Basic Arcade Demo Help

Post by jpatten » Fri Jun 08, 2012 4:16 am

Hi Malte...

Just jumping back into this again. I have updated the AE animation commands to use the newer calls, however I'm not sure if I'm coding this in the most appropriate way.

Here is my card script so far:

Code: Select all

on checkme
  if the flag of btn "startGame" is false then exit checkme
  
 lock screen

 repeat for each line theShot in the allshots of this cd
    if there is a btn ID theShot then 
      if theShot is not among the lines of gotTheMessage then
        repeat for each line theEnemy in the allEnemies of this cd
          if circleCollide(the loc of img ID theEnemy,the loc of btn ID theShot,30) then 
            if the visible of img ID theEnemy then
              send moveLinearMoveDone to btn ID theShot
            end if
            hide img ID theEnemy
            --add 1 to cd fld "score"
            --set the backgroundcolor of grc ID theEnemy to red
          end if
        end repeat
put the long ID of btn ID theShot into tBulletLongID
put cd fld "theAngle" into tBulletAngle
get pointOnCircle(loc of last btn, tBulletAngle,1200)
put it into tTargetEnd

send "aeMoveTo " & "the long ID of btn ID theShot,"  & tTargetEnd & ",1000" to btn ID theShot

      end if
    end if
  end repeat

put the allshots of this cd into newShots
  repeat for each line theShotToDelete in the pendingDeletitions of this cd
    filter newShots without theShotToDelete
    if there is a btn ID theShotToDelete then
       --DeleteOffScreenBullet
      --delete btn ID theShotToDelete
    end if
  end repeat
  set the allshots of this cd to newShots
  set the pendingDeletitions of this cd to empty

  repeat for each line theEnemy in the allEnemies of this cd
    send movePolygonal to img ID theEnemy
  end repeat
  
  wait 0 with messages
  unlock screen
  if the flag of btn "startGame" then send checkme to me in 30 milliseconds
end checkme

on moveLinearMoveDone
  if the name of target contains "bullet" then
    put the pendingdeletitions of this cd into allDeletitions
    put cr&the ID of the target after allDeletitions
    if line 1 of allDeletitions is empty then delete line 1 of allDeletitions
    set the pendingdeletitions of this cd to alldeletitions
  end if
end moveLinearMoveDone

on createShot
   
   lock screen
   lock messages
   
   clone btn "bulletTemplate" 
   put the ID of it into newShot
   put the ticks into tTicks
   set the name of btn ID newShot  to "bullet"& tTicks
   
   put the bulletList of current Card into tbulletList
   put the short name of btn ID newShot & cr after tBulletList
   
   if line 1 of tBulletList is empty then delete line 1 of tBulletList
   set the bulletList of this cd to tBulletList
   
   unlock messages
   unlock screen
   send initMove to btn ID newShot
end createShot

on initMove
  put the allshots of this cd into newShots
  put cr&the ID of the target after newShots
  if line 1 of newShots is empty then delete line 1 of newShots
  set the allshots of this cd to newShots
end initmove


on keydown TheKey
   if theKey = space then
     createshot
      end if
end keydown

--on mouseDown
--  --createShot
--end mouseDown

--on mouseStillDown
--  createShot
--end mouseStillDown



on mouseDoubleDown
  createShot
end mouseDoubleDown

on mouseDoubleUp
  
end mouseDoubleUp


on increaseEnergy
   if the energy of this cd<20 then
      set the energy of this cd to the energy of this cd+0.1
      set the thumbPos of sb "energy" to the energy of this cd
   end if
   if the flag of btn "startgame" then send increaseEnergy to me in 100 milliseconds
end increaseEnergy

on DeleteOffScreenBullet
   put the bulletList of current card into tBullets
   --repeat  for each line in tBullets
   put 1 into x
   repeat for number of lines in tBullets
      put line x of tBullets  into tTargetBullet
      
--put the short name of last btn into tTargetBullet
put lineoffset(tTargetBullet,tBullets) into tOffset -- get the matchingline number in tButtons
if tOffset > 0 then -- if there was a match...
         if the left of button tTargetBullet > the right of this card or the right of button tTargetBullet < 0 or the bottom of button tTargetBullet< 0 or the top of button tTargetBullet> the bottom of this card then

               delete line tOffset of tBullets -- remove the button name from the list
            --set the bulletList of current card to tBullets
delete button tTargetBullet -- delete the button
end if
end if
add 1 to x
end repeat
            set the bulletList of current card to tBullets

end DeleteOffScreenBullet
My script allows my "bullets" to be contolled by the direction controller. I can "steer" my shots. Not too big of deal, as I can see how this feature might be useful in another game environment if you could slow down the speed of the animated object ;-)

The part I'm stuck on now is how to delete the "bullet" once it has cleared the window. Not sure how to do that as my attempts have thrown up errors.

I've attached a copy of the project so far.

Thank you!
Attachments
ArcadeTest3.livecode.zip
(20.93 KiB) Downloaded 590 times

jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Re: Basic Arcade Demo Help

Post by jpatten » Sat Jun 09, 2012 6:28 am

Okay, simplified this down to its most basic parts and I know the problem is related to having more than one "bullet" on the card at a time. LiveCode throws up an AE error when it has to run a check on multiple "bullets" within the visible window.

Here is my code

Code: Select all

on keyDown theKey
   if theKey = space then
      createshot
      end if
end keyDown

on createShot
   lock screen
   lock messages
   
   clone btn "bulletTemplate"
   put the id of it into newShot
   
   put the BulletList of current card into tBulletList
   put newShot & cr after tBulletList
   if line 1 of tBulletList is empty then delete line 1 of tBulletList
   set the Bulletlist of this card to tBulletList
   
   set the name of btn id newshot to "bullet"
   set the loc of btn id newShot to the loc of grc "shooter"
   put the long ID of btn id newShot into tLongID
   
   put cd fld "theAngle" into tBulletAngle
   
   get pointOnCircle(loc of last btn, tBulletAngle,1200)
   put it into tTargetEnd
   
   aeMoveto tLongID,tTargetEnd,1000
   DeleteBullet
end createShot

on DeleteBullet
   put the bulletList of current card into tBullets
   put 1 into x
   repeat for number of lines in tBullets
      put line x of tBullets into tTargetBullet
      put lineOffset(tTargetBullet, tBullets) into tOffset -- get the matching line number of tBullets
      if tOffSet > 0 then
         if the left of btn id tTargetBullet > the right of this card or the right of button id tTargetBullet < 0 or the bottom of button id tTargetBullet < 0 or the top of button id tTargetBullet > the bottom of this card then
            delete line tOffset of tBullets
            delete button id tTargetBullet
         end if
      end if
      add 1 to x
   end repeat
   set the bulletlist of current card to tBullets
   
end DeleteBullet
How do I create code that does not trip over itself?

Thank you!
Attachments
AnimationTest.livecode.zip
(1.92 KiB) Downloaded 468 times

jpatten
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

Re: Basic Arcade Demo Help (SOLVED)

Post by jpatten » Sun Jun 10, 2012 4:31 am

I believe I discovered a solution. Apparently if I make AnimationEngine wait, if I slow it down, I can get my animated object, "bullet," to delete itself without throwing and AE error in the script editor window. Here is the code I used:

Code: Select all

on keyDown theKey
   if theKey = space then
      createshot
      end if
end keyDown

on createShot
   lock screen
   lock messages
   clone btn "bulletTemplate" 
   put the id of it into newShot
   put the BulletList of current card into tBulletList
   put newShot & cr after tBulletList
   if line 1 of tBulletList is empty then delete line 1 of tBulletList
   set the Bulletlist of this card to tBulletList
   set the name of btn id newshot to "bullet"
   set the loc of btn id newShot to the loc of grc "shooter"
   put the long ID of btn id newShot into tLongID
   put cd fld "theAngle" into tBulletAngle
   get pointOnCircle(loc of last btn, tBulletAngle,1200)
   put it into tTargetEnd
   if  there is a btn id newShot then
      aeMoveto tLongID,tTargetEnd,1000
      send DeleteBullet to btn id newShot in 2 seconds -- This was the solution. I had to make it wait longer than 30 milliseconds. 
   end if
end createShot


on DeleteBullet newShot
 put the bulletList of current card into tBullets
   put the ID of target into tTargetBullet
      if there is a btn id tTargetBullet then
     if the left of btn id tTargetBullet > the right of this card or the right of button id tTargetBullet < 0 or the bottom of button id tTargetBullet < 0 or the top of button id tTargetBullet > the bottom of this card then
             put the long id of btn id tTargetBullet into tLongIDofButton
            delete line 1 of tBullets
            delete button id tTargetBullet
         end if
      end if
set the bulletlist of current card to tBullets
end DeleteBullet

Post Reply

Return to “Animation Engine”