Post new topic    
Liquid Metal Slime
Send private message
Help. Trying to make eraser tool. 
 PostMon Nov 18, 2013 4:02 am
Send private message Reply with quote
I have been trying to make a tool in my program which erases the slice that is at mouse cursor position (x,y). This is what I have so far:

Code:

script, erase slice, begin
  if (slice collide point (sl, mouse pixel x + camera pixel x + p, mouse pixel y + camera pixel y + q) == true)  then(
    erasable sl := slice at pixel (sl, mouse pixel x + camera pixel x + p, mouse pixel y + camera pixel y + q)
   free slice (erasable sl)
  )
end

... ... ...

while (mouse button (left button) == true) do(
           if (tool == 0) then(
           set slice visible(cursor, on)
           sl := load large enemy sprite(a)
           set horiz anchor(sl, edge:center)
              set vert anchor(sl, edge:center)
           update stamp
           update cursor
           cursor visibility
           slice to front(sl)
           slice to front(cursor)
           )
           if (tool == 1) then(
           erase slice
           set slice visible(cursor, on)
           update cursor
           cursor visibility
          
           slice to front(cursor)
           )

... ... ...


The error I'm getting is when I try to use the eraser tool in the program is "free slice: invalid slice handle 0"

I'm not sure how to prevent this, as far as I can see my code is only supposed to be carried out if a sprite does in fact exist at (x,y) so why does this happen? Not only that but when I do have a slice at position (x,y) I still get this error. It's as if the game does not recognize my slices are there...
⊕ 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
Super Slime
Send private message
 
 PostMon Nov 18, 2013 4:21 am
Send private message Reply with quote
Try "if (slice exists(erasable sl)) then (free slice(erasable sl))"
Mega Tact v1.1
Super Penguin Chef
Wizard Blocks
Liquid Metal Slime
Send private message
 
 PostMon Nov 18, 2013 4:55 am
Send private message Reply with quote
Mogri wrote:
Try "if (slice exists(erasable sl)) then (free slice(erasable sl))"


My version of OHRRPGCE does not recognize this as a coding function. Is this in the Nightly version or something?
⊕ 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
 
 PostMon Nov 18, 2013 5:10 am
Send private message Reply with quote
Code:
slice is valid()
Super Slime
Send private message
 
 PostMon Nov 18, 2013 5:59 am
Send private message Reply with quote
Ah yes, that
Mega Tact v1.1
Super Penguin Chef
Wizard Blocks
Metal King Slime
Send private message
 
 PostMon Nov 18, 2013 3:41 pm
Send private message Reply with quote
You're misusing slice collide point and slice at pixel. First of all, both of them take a corredinate on the screen (ie 0,0 is the top left of the screen), so you should not be adding camera pixel x and camera pixel y (these are used for translating between map coordinate and screen coordinates, but mouse pixel x/y already return screen coordinates).

Secondly "slice collide point" only tests a single slice for collision. I assume that "sl" here is the slice to which all your stamps are parented. Maybe it's a container slice that covers the whole screen? If so, the "slice collide point" would always return true.

In this case you only need "if (erasable sl)) then (free slice(erasable sl))". "slice at pixel" returns false if it doesn't find anything.
Display posts from previous: