delete me while running

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
john-dev
Posts: 8
Joined: Sun Apr 14, 2013 3:38 pm

delete me while running

Post by john-dev » Sun Apr 14, 2013 3:47 pm

Hello,

i got a problem deleteing an image, i guess it's simple but i cant get it working.
I am creating images on the fly and attach a mousedown/up handler to those.

put "do q_open_object(the id of me)" into testt
put "on mouseDown" & cr & testt & cr & "end mouseDown" into theScript
set the script of templateImage() to theScript

Up to now, everything is working just fine.
The q_open_object function calls other functions.
One of those is called reset_objectthumbs:

Code: Select all

function reset_objectthumbs 
   local iTmp
   put 1 into x
   repeat the number of images in group "object_thumbs"
      if exists (image x of group "object_thumbs") then
         put the id of image x of group "object_thumbs" into iTmp
         if exists (image id iTmp) then
            try
               delete image id iTmp
           catch someError
               add 1 to x
           end try
         end if
      end if
   end repeat
   put false into toImage
   put 0 into modulujungex
   put 0 into modulujungey
end reset_objectthumbs
This function try's to delete the image, the on mouseDown handler is attached to (the one who calles the function, nested) and of course this wont work.
I guess it's basic (i am new to livecode), but how can i call that function and end the mousedown/up event before the function completed?

Thanks in advanced,
john

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: delete me while running

Post by sturgis » Sun Apr 14, 2013 4:05 pm

Ok, so your script in the mouseup ends up being:

Code: Select all

on mouseDown
    do q_open_object(the id of me)
end mouseDown
First thing, don't use "do" for this. Do is basically used to evaluate a string as if its a script. Since it is just a function and you dont' have any special need to use do, it will just slow things down and isn't necessary in this case. Also, you're calling a function, so the engine expects a value to be returned, yet if I understand how things are set up, you don't do anything with a returned value. This is asking for trouble. With a function you need to "get" it and whatever is returned will end up in the special variable IT or you need to "put" it into something, or it needs to be used as a conditional.. In some way the return value needs to be handled.

The first thing I would do is change it to a handler if you're not returning a value. Then, to get around the issue of "can't delete myself" you can use a send in time to get around the issue. Make sure the script to do the deletion is not in the object being deleted of course, then in the object something like

Code: Select all

send "handlertocall (the long id of me)" to this card in 100 milliseconds
This will add the call to the message queue and give plenty of time (way more than enough in most cases) for the mousedown handler to exit.

john-dev
Posts: 8
Joined: Sun Apr 14, 2013 3:38 pm

Re: delete me while running

Post by john-dev » Sun Apr 14, 2013 4:31 pm

hey sturgis,

using do is the failure of someone, using livecode since 2 days ;)
But i actually knew that functions are used if we expect a value in return, dont know why i used it..

wel it's working with that delay, but isn't that hardwar depending, wheather 10 ms are enough or not?

thanks for explaining this to me btw!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: delete me while running

Post by sturgis » Sun Apr 14, 2013 4:38 pm

I haven't tested, it might be sufficient to just send "whatever" to card "whatever" in 0 milliseconds as long as there is nothing in the mousedown that will allow it to fire before the mousedown completes. As mentioned though I haven't tested. Even if there is a bit of overlap there though (as in the engine still finishing mousedown cleanup when it fires) 100 ms is most likely WAY to large a number. 10ms is probably a safe bet for everything to be settled where the object can be safely deleted.

I did test with dispatch, so do believe a minimal amount of time IS required for it to work reliably. (dispatch should pop a message to the end of the queue, but it does occur too fast for the delete to work)

john-dev
Posts: 8
Joined: Sun Apr 14, 2013 3:38 pm

Re: delete me while running

Post by john-dev » Mon Apr 15, 2013 4:41 pm

Me again,

i have another problem and i dont want to open another post..
I have a shaped main stack. things are working fine until i resize this window programmatically.
as you can see in the image attached, there is a weird "graphic"-like white half-trans rectangle.
the height and width seem to be the same as the stack's size, without the windowshape.

as soon as i set another programm (like firefox) as active window and switch back, this rectangle dissappears...

any ideas?
Attachments
weirdwindows.jpg

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: delete me while running

Post by sturgis » Tue Apr 16, 2013 2:17 am

Silly though it sounds you might try a system restart (not just lc) I've seen some pretty strange things like that disappear after a restart.

john-dev
Posts: 8
Joined: Sun Apr 14, 2013 3:38 pm

Re: delete me while running

Post by john-dev » Wed Apr 17, 2013 8:16 am

hey,

good idea, bad result.. it didnt work out.. this also appears in the standalone version btw!

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: delete me while running

Post by Klaus » Wed Apr 17, 2013 11:50 am

HI John,

can you please show us your "resize" script?
Looks like LC is "losing" the connection to the correct windowshape graphic.

Best

Klaus

Post Reply

Return to “Mac OS”