Slice does not exist error, but I'm have checks in place...

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: 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:

Slice does not exist error, but I'm have checks in place...

Post by sheamkennedy »

I've got a lot of stuff coded for my game that revolves around menus appearing on screen and the player being able to interact with them. Problem is that I occasionally get errors saying "slice does not exist" when my scripts are either supposed to destroy a menu slice, or do stuff like move slice below another slice.

I realize there is a way for me to check if slices exist prior to carrying out these types of codes with scripting like:

Code: Select all

if(ItemMenu && ItemFrame) then( 
    move slice below (ItemMenu, ItemFrame) 
  ) 
...but for some reason this isn't working. I still occasionally get these errors and I'm very positive that I've covered all my bases by implementing checks to make sure the slices exist before hand. Any idea why this could still be happening? Also the error is hard to reproduce, seems to happen when I least expect it.
⊕ 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
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Code: Select all

if(ItemMenu && ItemFrame) then(
This checks that the handle stored in the ItemMenu and ItemFrame variables is not zero.

In many cases that check is good enough, but if you have a situation where the slice might have been freed elsewhere (such as by freeing its parent or grandparent) without clearing the handle number out of the variable, you might need:

Code: Select all

if(slice is valid(ItemMenu) && slice is valid(ItemFrame)) then(
The "slice is valid" command can take a non-zero handle and check if the slice it used to point to still exists.

This isn't 100% foolproof, since if you are in a situation where you are rapidly creating and destroying massive numbers of slices, an invalid handle number might get recycled by a newly created slice, but I think it is extremely unlikely that your script is doing anything that would trigger that rare edge-case.
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 »

Awesome, I'll try implementing this for all my checks then let you know if any other issues arise with it.
⊕ 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
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

It's worth noting that "a massive number" here means 5000. However this is the behaviour in nightlies since a couple months ago only; before then "slice is valid" was far closer to being useless.
Last edited by TMC on Sat Apr 04, 2015 2:54 pm, edited 1 time 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 »

Thanks, I'll keep that in mind. I do actually have a code which creates slices for every wall in the map. Still I don't think I'll exceed 5000 slices since I'll limit the size of each map area. On top of that I don't even know if I'll be using wall slices for collision detection since it may not be suitable for the way I'm making my game.
⊕ 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
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The totally correct solution is to never use sliceisvalid, and instead set the variable to zero when you delete the slice it points to. In most case you know when you're deleting it.
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yeah, I agree. I prefer to think of "slice is valid" as more of a debug tool to help find out what is wrong , rather than something you should use all the time.
Post Reply