Page 1 of 1

How do you stop execution of a script?

Posted: Sat Apr 13, 2013 6:34 pm
by ianpiper
I am following lesson 3 of SheepHerder Academy. I must have made some sort of error, because I keep getting an error window popping up.

Code: Select all

executing at 6:20:31 PM
Type	Chunk: can't set property
Object	card id 1002
Line	set the loc of the target to the mouseLoc
Hint	mouseMove
But this happens even when I am in edit mode - whenever I hover over the card the Errors window pops up with a new copy of the same error. I believe that my code is the same as that in the tutorial 3 pdf, except that I have also put in an onMouseDown method (this isn't in the tutorial code but without this I can't drag anything). Here is my onMouseMove method.

on mouseMove
if sImASheep is true then
set the loc of the target to the mouseLoc
if intersect (the target, Graphic "pen", 255) and the clsSheep of the target is true then
set the backgroundcolor of the graphic "pen" to "red"
else
set the backgroundcolor of the graphic "pen" to "blue"
end if
end if
end mouseMove

I'm sure I've done something wrong, but a steer would be greatly appreciated. At the least it would be good to know how to really stop execution of the script.

Thanks

Re: How do you stop execution of a script?

Posted: Sat Apr 13, 2013 7:26 pm
by dave_probertGA6e24
Quick question...

Where have you put the mouseMove handler? On the stack, card or object level?

It's likely that the 'target' is not what you may think it is. Probably best to modify that handler to do a

Code: Select all

put the target & cr after msg
in place of what it currently does - just so you can monitor what the value of target is. If it changes to anything other than what you are expecting then you will have found the problem.

It's likely that you may need to check what the target name is and only do the intersect stuff, etc if it is one of the expected items.

I don't know the Sheepherder code at all, but I'm guessing that the clsSheep property is something that identifies a Sheep item. You might want to do the check for that before you do anything else with the target - ie put that before the 'set the loc...' line.

These are only some suggestions.

Regarding the execution of the script even while in edit mode - there are ways to detect edit mode and wrap your handler code in the detection stuff. I too am not a fan of having my code run while in edit mode, but I seem to be in the minority!!! Look for other, earlier, messages by me to see some of the answers that were given ;)

If you persevere then you will slowly get used to it and will learn to "Save Often and Keep Calm", but most of all always save before running a test, and even when changing cards/stacks (in case an 'on openCard' handler fires and locks up LC) If script seems to cause a lock-up then you might be able to interrupt it via Cmd-. or Ctrl-. (. = Full stop/point/dot on the keyboard)

Cheers,
Dave

Re: How do you stop execution of a script?

Posted: Sun Apr 14, 2013 1:42 am
by ianpiper
Thanks for the reply.

I'm just following the code in the tutorial. I think my code matches the code in the tutorial (after all, I cut and pasted it once my own code failed), but it doesn't work. And it's really not clear where to go with this. The mouseMove handler is in the card script. Sadly I have no idea how to determine what the target is - I can't figure out where to put the code you have suggested. And there is not much point in going on to tutorial 4, which builds on this, if this doesn't work.

Re: How do you stop execution of a script?

Posted: Sun Apr 14, 2013 2:08 am
by dunbarx
Hi.

What Dave was getting at was this: What if the target was a card? Then the loc would not make much sense. The error message indicates as much.

In your mouseMove handler, he suggested that you do something like this:

on mouseMove
if sImASheep is true then
put the name of the target -- to make sure it is a card object, and NOT the card itself
end mouseMove

Try this script. watch the message box, and you will see that the target changes as the mouse moves over various card objects, but reverts to the card itself if there are no objects under the cursor. The engine will throw an error if you try to set the loc of the card.

Bet you a buck this is the problem. Do you see the way out of it?

Craig Newman

Re: How do you stop execution of a script?

Posted: Sun Apr 14, 2013 3:14 am
by Simon
Hi ianpiper,
What they said is good.
But, I'm thinking more of your Subject line rather than solving your issue with sheep dip.

Look up "breakpoint" in the dictionary. Also if you click on a line number (the actual number) a red dot will show up, both will pause the script execution and allow you to step through your code.

Simon

Re: How do you stop execution of a script?

Posted: Sun Apr 14, 2013 4:19 pm
by sturgis
sImASheep should be a property of the sheep graphic. You're treating it like a variable, and if the variable is true for that script, it is true no matter what object is being pointed at, hence the error.


When the template image for the sheep is created, he manually creates a property. (not sure it is sImASheep, but as long as the name is consistent, it should be ok)

Not looking at the code directly, but it probably has something like

if the sImASheep of the target then....



end if

In this way it is checking the property of the current target, and if that property is set to true, then it does all its stuff. As mentioned elsewhere in the thread, you can't set the loc of the card, so any time you're moving the mouse over an empty card, if the variable you are checking (sImAAheep) is true you'll have an error. This is why the property is so important. Its associated with the object in question and helps you know that you are indeed pointing at a sheep object. No property, or property set to false = not a sheep.

Re: How do you stop execution of a script?

Posted: Sun Apr 14, 2013 6:41 pm
by jacque
You can stop your own handlers from executing by clicking the Messages button in the toolbar. That lets the IDE continue to work but doesn't send any messages to your stack. Remember to turn on Messages again later or nothing will work.

You can have the best of both worlds this way.