Post new topic    
Liquid Metal Slime
Send private message
Possible bug discovered 
 PostTue Jan 20, 2015 8:03 pm
Send private message Reply with quote
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
Liquid Metal King Slime
Send private message
 
 PostTue Jan 20, 2015 8:19 pm
Send private message Reply with quote
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.
Liquid Metal Slime
Send private message
 
 PostTue Jan 20, 2015 8:31 pm
Send private message Reply with quote
@Bob the Hamster:

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

Here's the script so you can further dissect:

Code:

    variable (collection)
    if(key is pressed(key:X)) then(
    if(isShooting <> 1) then(
      isShooting := 1
          #If hero is facing right, then shoot bullet to the right
          if(hero direction == right) then(
            collection := load slice collection(10)
            Bullet := lookup slice(sli:Bullet1, collection)
            #Parent bullet to hero so that the bullet originates from the hero
            set parent(Bullet, get hero slice (0))
            set slice edge x (Bullet, edge:top, 0)
            set slice edge y (Bullet, edge:top, -15)
            set slice velocity x (Bullet, 20, 10)
            set slice velocity y (Bullet, 0, 10)
            center slice (Bullet)
            isShooting := 1
            BulletWasJustShot := 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
          )
          if(hero direction == left) then(
            collection := load slice collection(10)
            Bullet:= lookup slice(sli:Bullet1, collection)
            set parent(Bullet, get hero slice (0))
            set slice edge x (Bullet, edge:top, 0)
            set slice edge y (Bullet, edge:top, -15)
            set slice velocity x (Bullet, -20, 10)
            set slice velocity y (Bullet, 0, 10)
            center slice (Bullet)
            isShooting := 1
            BulletWasJustShot := 1
            Bullet Timer
            exit script
          )
          if(hero direction == up) then(
            collection := load slice collection(11)
            Bullet:= lookup slice(sli:Bullet2, collection)
            set parent(Bullet, get hero slice (0))
            set slice edge x (Bullet, edge:top, 0)
            set slice edge y (Bullet, edge:top, -15)
            set slice velocity x (Bullet, 0, 10)
            set slice velocity y (Bullet, -20, 10)
            center slice (Bullet)
            isShooting := 1
            BulletWasJustShot := 1
            Bullet Timer
            exit script
          )
          if(hero direction == down) then(
            collection := load slice collection(11)
            Bullet:= lookup slice(sli:Bullet2, collection)
            set parent(Bullet, get hero slice (0))
            set slice edge x (Bullet, edge:top, 0)
            set slice edge y (Bullet, edge:top, -15)
            set slice velocity x (Bullet, 0, 10)
            set slice velocity y (Bullet, 20, 10)
            center slice (Bullet)
            isShooting := 1
            BulletWasJustShot := 1
            Bullet Timer
            exit script
          )
          isShooting := 0
    )
    )

⊕ 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
Liquid Metal King Slime
Send private message
 
 PostTue Jan 20, 2015 9:12 pm
Send private message Reply with quote
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:

  variable (collection)
  if(key is pressed(key:X)) then(
    if(isShooting <> 1) then(
      isShooting := 1
      collection := load slice collection(10)
      Bullet := lookup slice(sli:Bullet1, collection)
      #Parent bullet to hero so that the bullet originates from the hero
      set parent(Bullet, get hero slice (0))
      center slice (Bullet)
      switch(hero direction) do(
        case(right) do(
          set slice edge x (Bullet, edge:top, 0)
          set slice edge y (Bullet, edge:top, -15)
          set slice velocity x (Bullet, 20, 10)
          set slice velocity y (Bullet, 0, 10)
        )
        case(left) do(
          set slice edge x (Bullet, edge:top, 0)
          set slice edge y (Bullet, edge:top, -15)
          set slice velocity x (Bullet, -20, 10)
          set slice velocity y (Bullet, 0, 10)
        )
        case(up) do(
          set slice edge x (Bullet, edge:top, 0)
          set slice edge y (Bullet, edge:top, -15)
          set slice velocity x (Bullet, 0, 10)
          set slice velocity y (Bullet, -20, 10)
        )
        case(down) do(
          set slice edge x (Bullet, edge:top, 0)
          set slice edge y (Bullet, edge:top, -15)
          set slice velocity x (Bullet, 0, 10)
          set slice velocity y (Bullet, 20, 10)
        )
      )
      BulletWasJustShot := 1
      Bullet Timer
    )
  )


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"
Liquid Metal Slime
Send private message
 
 PostTue Jan 20, 2015 9:58 pm
Send private message Reply with quote
Hmm, so maybe the solution would be to initialize isShooting to be zero within the map autorun...?

Here's the timer script nonetheless:
Code:

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 (BulletWasJustShot == 1) then(
    BulletWasJustShot := 0
    set timer(0, 0, 10, @Bullet Timer)   
  ) else (
  free slice (Bullet)
  isShooting := 0
  BulletWasJustShot := 1
  )
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.
⊕ 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
Liquid Metal King Slime
Send private message
 
 PostTue Jan 20, 2015 11:05 pm
Send private message Reply with quote
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.
Liquid Metal Slime
Send private message
 
 PostWed Jan 21, 2015 10:05 pm
Send private message Reply with quote
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).
⊕ 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
Display posts from previous: