Invalid Slice Handle Error during collision test

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:

Invalid Slice Handle Error during collision test

Post by sheamkennedy »

In search of quicker help I am reposting this problem in it's own thread:

I wrote up what I think to be a simple collision test to see if my slice collision works. It looks like so:

Code: Select all

script, checkCollisions, begin
  if (SliceCollide (sli:Hitbox1, sli: Bullet1)) then ( 
    DestroyNPC (0) 
  )
end
This script is called in my autorun script. When I try to run this in game it gives the error:
Invalid slice handle 261

These slices do exist in my slice collections, so why the error? They have also been exported to an HSI included in my script to clarify things.

EDIT:
I have just updated my script to this. It got rid of the error but still no collision is recognized since the NPC is not being destroyed... Any ideas why? I'm positive these slices are making contact.

Code: Select all

script, checkCollisions, begin
  if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
    if (slice collide (sli:Hitbox1, sli:Bullet1)) then( 
      free slice (sli:Hitbox1)
      free slice (sli:Bullet1)
      DestroyNPC (0) 
    )
  )  
end
EDIT #2:
After further realizing that Gizmog and Urkel were discussing something like this earlier I have further revised my code to use handles rather than slices as I made this similar mistake. Still though I am having trouble with getting the code to work. Here's the latest revision of the code:

Code: Select all

script, checkCollisions, begin
  if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
    if (slice collide (LookUpSlice (sli:Hitbox1), LookUpSlice (sli:Bullet1)) == true) then( 
      destroy NPC (0) 
      play sound (4, false, true) 
    )
  )  
end
Last edited by sheamkennedy on Sun Jan 11, 2015 12:23 am, edited 2 times 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
Gizmog
Metal King Slime
Posts: 2615
Joined: Tue Feb 19, 2008 5:41 am

Re: Invalid Slice Handle Error during collision test

Post by Gizmog »

sheamkennedy wrote:

Code: Select all

script, checkCollisions, begin
  if (slice is valid(sli:Hitbox1) && slice is valid(sli:Bullet1)) then(
    if (slice collide (LookUpSlice (sli:Hitbox1), LookUpSlice (sli:Bullet1)) == true) then( 
      destroy NPC (0) 
      play sound (4, false, true) 
    )
  )  
end
Why are you still checking two different things? You're checkin if there's a slice with the handle stored in Sli:HitBox1 and a slice with the handle stored in Sli:Bullet1 and then you're using those same values as slice look-up codes which are a different thing. Try making them both lookupslice and see what happens.
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 »

So I think this is what you mean:

Code: Select all

script, checkCollisions, begin
  if ((slice is valid(LookUpSlice (sli:Hitbox1)) && slice is valid(LookUpSlice (sli:Bullet1))) == true) then(
    if (slice collide (LookUpSlice (sli:Hitbox1), LookUpSlice (sli:Bullet1)) == true) then( 
      destroy NPC (0) 
      play sound (4, false, true) 
    )
  )  
end
Just tried it. No noticeable change in gameplay though.

Also I probably don't need slice is valid anymore do I...
Last edited by sheamkennedy on Sun Jan 11, 2015 12:57 am, 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
Gizmog
Metal King Slime
Posts: 2615
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Hit Ctrl+F4 and take a screenshot, maybe the slices aren't actually there somehow? Or set up some kind of script to make the slices in question do something really really visible and obvious so you know whether or not they exist and whether or not the script is addressing them correctly?
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 »

Alright so I took your advice and made a small code to see if the slices existed.

Here's the code I used to check it:

Code: Select all

    
if(key is pressed(key:O)) then(
  stop slice (lookup slice(sli:Bullet1))
  stop slice (lookup slice(sli:Hitbox1))
)
When I click "O" it seems that neither the bullet being fired or the Hitbox bound to the NPC stops... So visibly I'm seeing what I think to be a bullet and a hitbox on screen, yet they are not what I'm referring to in script I guess.
⊕ 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
Gizmog
Metal King Slime
Posts: 2615
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Did you load these slices via collection, maybe?

When you load a slice collection like uhh.. let's say SliceCollection 1 is a single rectangle slice.

Code: Select all

Bullet := LoadSliceCollection (1)
The slice it's referring to isn't that single rectangle slice, but rather a container slice that holds everything in that collection. So if you were to do

Code: Select all

SetRectFGColor (Bullet,255,255)
You'd get some kind of an error for trying to set the color of a container, rather than the rectangle inside of it.

It's sloppy, but sometimes to get around that I do like

Code: Select all

Bullet := LoadSliceCollection (1)
Bullet := FirstChild (Bullet)
And that would set it to the first child, aka the single rectangle slice.
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 »

I tried further to figure this out. I believe you are right. I have loaded my stuff in the form of collections. All my hitboxes in one collection. Bullets others.

Perhaps I should give all parts of my code to clarify things. I'm almost considering making a simple shooting game from scratch so I don't confuse myself with other elements of my code.

Code: Select all

#Attach hitbox's to enemies
variable(hitbox, collection, hitboxParent1, hitboxParent2 , hitboxParent3, hitboxParent4)
collection := load slice collection(12)
  #Guard 1
  hitbox:= lookup slice(sli:Hitbox1, collection)
  setparent (hitbox,GetNPCSlice (0)) 
  
  set slice edge x (hitbox, edge:top, 3)
  set slice edge y (hitbox, edge:top, -13)

Code: Select all

 variable(collection, sl, Bullet)
    if(key is pressed(key:X)) then( 
        if&#40;isShooting <> 1&#41; then&#40;
          isShooting &#58;= 1
          if&#40;hero direction == right&#41; then&#40; 
            collection &#58;= load slice collection&#40;10&#41;
            sl &#58;= lookup slice&#40;sli&#58;Bullet1, collection&#41;
            set parent&#40;sl, lookup slice&#40;sl&#58;walkabout layer&#41;&#41;
            put slice &#40;sl, hero pixel X &#40;me&#41;, hero pixel Y &#40;me&#41;&#41;
            set slice velocity x &#40;sl, 20, 10&#41;
            set slice velocity y &#40;sl, 0, 10&#41;
            isShooting &#58;= 1
            wait for slice&#40;sl&#41;
            free slice&#40;sl&#41;
            isShooting &#58;= 0
            exit script
          &#41;
EDIT: and here's the slice tree
Image
Last edited by sheamkennedy on Sun Jan 11, 2015 3:33 am, edited 3 times 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
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

I feel like I've made some progress but I'm still getting an undesired result. Could you look at my code to see if I'm making a mistake.

I have changed the script so the Bullet is a child of the hero, and the hitbox is the child of the NPC. Then I compare the first child of hero and of NPC to check for collision. Still not working. I think I'm reading the slice tree properly but have provided it. Also I will provide my latest collision check code:

Image

Code: Select all

script, checkCollisions, begin
  if &#40;&#40;slice is valid&#40;LookUpSlice &#40;first child&#40;GetNPCSlice &#40;0&#41;&#41;&#41;&#41;&#41; && &#40;slice is valid&#40;LookUpSlice &#40;first child&#40;get hero slice &#40;0&#41;&#41;&#41;&#41;&#41; == true&#41;  then&#40;
    if &#40;slice collide &#40;LookUpSlice &#40;first child&#40;GetNPCSlice &#40;0&#41;&#41;&#41;, LookUpSlice &#40;first child&#40;get hero slice &#40;0&#41;&#41;&#41;&#41; == true&#41; then&#40; 
      destroy NPC &#40;0&#41; 
      play sound &#40;4, false, true&#41; 
    &#41;
  &#41;  
end
EDIT: I found some key information. When I alter the code slightly to this the sound is played when my hero is colliding with the NPC. But this shouldn't be right... I'm under the impression it should only be when their first childs are colliding...

Code: Select all

script, checkCollisions, begin
  if &#40;&#40;slice is valid&#40; &#40;first child&#40;GetNPCSlice &#40;0&#41;&#41;&#41;&#41;&#41; && &#40;slice is valid&#40; &#40;first child&#40;get hero slice &#40;0&#41;&#41;&#41;&#41;&#41; == true&#41;  then&#40;
    if &#40;slice collide &#40;&#40;first child&#40;GetNPCSlice &#40;0&#41;&#41;&#41;, &#40;first child&#40;get hero slice &#40;0&#41;&#41;&#41;&#41; == true&#41; then&#40; 
      #destroy NPC &#40;0&#41; 
      play sound &#40;4, false, true&#41; 
    &#41;
  &#41;  
end
Last edited by sheamkennedy on Sun Jan 11, 2015 4:09 am, 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
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Upon further inspection of the slice tree it would seem that the Bullet is not a child of the hero but rather a sibling. Although I can't understand why... I had parented the bullet to the hero, thus the bullet should be the heros child.
⊕ 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
Gizmog
Metal King Slime
Posts: 2615
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Apparently you parented the bullet to the container of the hero and not the visible walkabout component? But! Now that we know where it is, a

Code: Select all

LookUpSlice &#40; sli&#58;Bullet1,GetHeroSlice &#40;0&#41; &#41;
Oughta find the first (And in this case, only) slice attached to the hero with the lookup code Sli:Bullet1 which should get things working.
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 »

Gizmog wrote:Apparently you parented the bullet to the container of the hero and not the visible walkabout component? But! Now that we know where it is, a

Code: Select all

LookUpSlice &#40; sli&#58;Bullet1,GetHeroSlice &#40;0&#41; &#41;
Oughta find the first (And in this case, only) slice attached to the hero with the lookup code Sli:Bullet1 which should get things working.
I replaced the parts of my code with that lookup, and a similar lookup for hitbox. Now it's not registering anything unfortunately. But I feel close to figuring this out.

Code: Select all

script, checkCollisions, begin
  if &#40;&#40;slice is valid&#40;lookup slice&#40;sli&#58;Bullet1, GetHeroSlice&#40;0&#41;&#41;&#41;&#41; && &#40;slice is valid&#40;lookup slice&#40;sli&#58;Hitbox1,GetNPCSlice&#40;0&#41;&#41;&#41;&#41;== true&#41;  then&#40;
    if &#40;slice collide &#40;lookup slice&#40;sli&#58;Bullet1,GetHeroSlice&#40;0&#41;&#41;, lookup slice&#40;sli&#58;Hitbox1,GetNPCSlice&#40;0&#41;&#41;&#41;  == true&#41; then&#40; 
      #destroy NPC &#40;0&#41; 
      play sound &#40;4, false, true&#41; 
    &#41;
  &#41;  
end
⊕ 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