Possible bug discovered

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Possible bug discovered

Post by sheamkennedy »

As some may know, I have just finished up making a projectile shooting on-keypress script. After messing around with shooting projectiles I have noticed that if I happen to be shooting projectiles while walking through a door to another map then my projectile shooting on keypress no longer works... Yet other onkeypress scripts do work, like holding down another key to "run."

Could this be a door related bug or something to do with my onkeypress script?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I would have to see more of the script to know.

Each map has its own "on keypress" script. Is the same script being used on both sides of the door?

Also, moving to another map may or may not cause the map layers to be destroyed and re-created, depending on a global bitset. This also implies that NPC slices will be recreated, so if you are using a slice handle that yoi stored when you were on the previous map, it might have gone stale when you changed maps.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

@Bob the Hamster:

I am using the same on-keypress script for both rooms.

Here's the script so you can further dissect:

Code: Select all

    variable (collection)
    if(key is pressed(key:X)) then( 
    if&#40;isShooting <> 1&#41; then&#40;
      isShooting &#58;= 1
          #If hero is facing right, then shoot bullet to the right
          if&#40;hero direction == right&#41; then&#40; 
            collection &#58;= load slice collection&#40;10&#41; 
            Bullet &#58;= lookup slice&#40;sli&#58;Bullet1, collection&#41;
            #Parent bullet to hero so that the bullet originates from the hero
            set parent&#40;Bullet, get hero slice &#40;0&#41;&#41; 
            set slice edge x &#40;Bullet, edge&#58;top, 0&#41; 
            set slice edge y &#40;Bullet, edge&#58;top, -15&#41; 
            set slice velocity x &#40;Bullet, 20, 10&#41; 
            set slice velocity y &#40;Bullet, 0, 10&#41; 
            center slice &#40;Bullet&#41;
            isShooting &#58;= 1
            BulletWasJustShot &#58;= 1
            Bullet Timer
            #Exit the script because we don't want the player to shoot a second bullet
            #facing a different direction in the coming if-statements
            exit script
          &#41;
          if&#40;hero direction == left&#41; then&#40;
            collection &#58;= load slice collection&#40;10&#41;
            Bullet&#58;= lookup slice&#40;sli&#58;Bullet1, collection&#41;
            set parent&#40;Bullet, get hero slice &#40;0&#41;&#41;
            set slice edge x &#40;Bullet, edge&#58;top, 0&#41; 
            set slice edge y &#40;Bullet, edge&#58;top, -15&#41; 
            set slice velocity x &#40;Bullet, -20, 10&#41;
            set slice velocity y &#40;Bullet, 0, 10&#41;
            center slice &#40;Bullet&#41;
            isShooting &#58;= 1
            BulletWasJustShot &#58;= 1
            Bullet Timer
            exit script
          &#41; 
          if&#40;hero direction == up&#41; then&#40;
            collection &#58;= load slice collection&#40;11&#41;
            Bullet&#58;= lookup slice&#40;sli&#58;Bullet2, collection&#41;
            set parent&#40;Bullet, get hero slice &#40;0&#41;&#41;
            set slice edge x &#40;Bullet, edge&#58;top, 0&#41; 
            set slice edge y &#40;Bullet, edge&#58;top, -15&#41; 
            set slice velocity x &#40;Bullet, 0, 10&#41;
            set slice velocity y &#40;Bullet, -20, 10&#41;
            center slice &#40;Bullet&#41;
            isShooting &#58;= 1
            BulletWasJustShot &#58;= 1
            Bullet Timer
            exit script
          &#41; 
          if&#40;hero direction == down&#41; then&#40;
            collection &#58;= load slice collection&#40;11&#41;
            Bullet&#58;= lookup slice&#40;sli&#58;Bullet2, collection&#41;
            set parent&#40;Bullet, get hero slice &#40;0&#41;&#41;
            set slice edge x &#40;Bullet, edge&#58;top, 0&#41; 
            set slice edge y &#40;Bullet, edge&#58;top, -15&#41; 
            set slice velocity x &#40;Bullet, 0, 10&#41;
            set slice velocity y &#40;Bullet, 20, 10&#41;
            center slice &#40;Bullet&#41;
            isShooting &#58;= 1 
            BulletWasJustShot &#58;= 1
            Bullet Timer
            exit script
          &#41;
          isShooting &#58;= 0
    &#41;
    &#41;
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hmmm... Nothing in there looks like it could cause the problem you describe. Can you show me the "Bullet Timer" script?

Also you mention other on-keypress effects like dashing still work, That would suggest to me that something is going wrong with the isShooting variable, so it never gets set back to zero.



By the way, you have a lot of lines duplicated for all four directions, so you could move the duplicate lines to the top, and only have the stuff that is different for different directions inside those if/then blocks.

also, "hero direction" can only return 4 possible values, and you have handled them all, so the "isShooting := 0" at the end of the script can *never* happen, and if you remove that, then all the "exit script" commands at the end of each direction are no longer needed, since this all happens in a single tick with no "wait" commands, it should be impossible for the hero to change directions mid-script. Does that make sense?

EDIT: to make it a little clearer, I re-wrote this script the way I would do it:

Code: Select all

  variable &#40;collection&#41;
  if&#40;key is pressed&#40;key&#58;X&#41;&#41; then&#40;
    if&#40;isShooting <> 1&#41; then&#40;
      isShooting &#58;= 1
      collection &#58;= load slice collection&#40;10&#41;
      Bullet &#58;= lookup slice&#40;sli&#58;Bullet1, collection&#41;
      #Parent bullet to hero so that the bullet originates from the hero
      set parent&#40;Bullet, get hero slice &#40;0&#41;&#41;
      center slice &#40;Bullet&#41;
      switch&#40;hero direction&#41; do&#40;
        case&#40;right&#41; do&#40;
          set slice edge x &#40;Bullet, edge&#58;top, 0&#41;
          set slice edge y &#40;Bullet, edge&#58;top, -15&#41;
          set slice velocity x &#40;Bullet, 20, 10&#41;
          set slice velocity y &#40;Bullet, 0, 10&#41;
        &#41;
        case&#40;left&#41; do&#40;
          set slice edge x &#40;Bullet, edge&#58;top, 0&#41;
          set slice edge y &#40;Bullet, edge&#58;top, -15&#41;
          set slice velocity x &#40;Bullet, -20, 10&#41;
          set slice velocity y &#40;Bullet, 0, 10&#41;
        &#41;
        case&#40;up&#41; do&#40;
          set slice edge x &#40;Bullet, edge&#58;top, 0&#41;
          set slice edge y &#40;Bullet, edge&#58;top, -15&#41;
          set slice velocity x &#40;Bullet, 0, 10&#41;
          set slice velocity y &#40;Bullet, -20, 10&#41;
        &#41;
        case&#40;down&#41; do&#40;
          set slice edge x &#40;Bullet, edge&#58;top, 0&#41;
          set slice edge y &#40;Bullet, edge&#58;top, -15&#41;
          set slice velocity x &#40;Bullet, 0, 10&#41;
          set slice velocity y &#40;Bullet, 20, 10&#41;
        &#41;
      &#41;
      BulletWasJustShot &#58;= 1
      Bullet Timer
    &#41;
  &#41; 
The switch/case/do structure is just a slightly different way to write the same if/then structure you had for checking the "hero direction"
Last edited by Bob the Hamster on Tue Jan 20, 2015 9:22 pm, edited 3 times in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Hmm, so maybe the solution would be to initialize isShooting to be zero within the map autorun...?

Here's the timer script nonetheless:

Code: Select all

script, Bullet Timer, begin
  #If the bullet was just shot, a timer which destroys the bullet begins, once the time
  #is up this script will retrigger causing the bullet to be destroyed and allowing the
  #player to shoot a new bullet
  If &#40;BulletWasJustShot == 1&#41; then&#40;
    BulletWasJustShot &#58;= 0
    set timer&#40;0, 0, 10, @Bullet Timer&#41;    
  &#41; else &#40;
  free slice &#40;Bullet&#41;
  isShooting &#58;= 0
  BulletWasJustShot &#58;= 1 
  &#41;
end 
And thanks for simplifying my directional script, I figured I'd get around to that sooner or later but usually write my scripts in very clunky ways to begin with.
Last edited by sheamkennedy on Tue Jan 20, 2015 9:59 pm, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Probably, yes, resetting isShooting to 0 when switching maps should help.

Also, looks like BulletWasJustShot is not needed at all. isShooting is good enough to do the job by itself.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Bob the Hamster wrote:Probably, yes, resetting isShooting to 0 when switching maps should help.

Also, looks like BulletWasJustShot is not needed at all. isShooting is good enough to do the job by itself.
Alright, that settles that issue.

Another thing I noticed after the issue was resolved is that if I click the shoot button rapidly while walking through the door the next map seems to let me shoot before the map is ready for me to do so. This causes "invalid slice handle 0" error messages. Now I know in must cases a player won't be button mashing while walking through a door, but still it makes me question whether there is an issue with doors in general. I figure I could add a wait on the start of the map autorun, or suspend player for a few ticks... but should doing so be necessary?

EDIT: Actually I just tried out both methods that I suggested. Neither seem to stop this error from occurring. This leads me to think that the problem is that the bullet slice being created before the door is entered is somehow interfering with the script on the map being entered. If there was such a thing as a map exit script I could just destroy all created slices before being transported to the next map... This seems tedious to do really. Please let me know if theres an easy solution, if the door mechanics will ever be updated to do this on their own, or if I have no idea what I'm talking about (because in all seriousness I'm just guessing at the problem here).
Last edited by sheamkennedy on Wed Jan 21, 2015 10:14 pm, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Post Reply