Strange behavior in the flow of a script

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Senelori
Posts: 3
Joined: Wed Mar 10, 2010 9:26 pm

Strange behavior in the flow of a script

Post by Senelori » Thu Mar 11, 2010 2:50 pm

Hi. I apologize for my English.
A question about a strange behavior in the writing of a script.
The script does not do anything useful, it is only to explain the problem.

Create a new stack. In the card create a field (for example call it "Dati") and create a check box (call it eg "Aim"). In the card script write this simple script:

Code: Select all

on mouseMove
   if the hilite of btn "aim" = false then  exit mouseMove
   add 1 to fld "Dati"   
end mouseMove

Run the script. If you activate the check box (true) when you move the mouse the counter increases its value. If you deactivate the check box (false) the counter stops.
Ok. It works, even if it does anything useful… :wink:

But now consider the following script: it is the same as the first example, and only moved the statement "if" after the "add".

Code: Select all

on mouseMove
   add 1 to fld "Dati"  
   if the hilite of btn "aim" = false then  exit mouseMove 
end mouseMove

Replace in the card script the previous script with this new and run again.
But now the counter is incremented always be that check box is activated or not.
When writing a program I can logically put a test where deemed appropriate (for example, after running some code at least once).
Why in this case does not work? Is there anything I don't know programming?

Thank you for your attention.

Senelori
Posts: 3
Joined: Wed Mar 10, 2010 9:26 pm

Re: Strange behavior in the flow of a script

Post by Senelori » Thu Mar 11, 2010 2:59 pm

I'm sorry: I was rude and I apologize.
I forgot to give you my information techniques.

iMac with OSx 10.6.2
revEnterprise 4.5.0-dp-2

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Strange behavior in the flow of a script

Post by bn » Thu Mar 11, 2010 3:16 pm

Hi Senelori,

welcome to the forum.
You add to the counter before you exit mouseMove. So it always has to add to the counter.
It is just the flow of the arguments that is the problem. You tell the mouseMove handler to add 1 to the counter and than you test for a condition, the mouseMove handler does as you tell him to. So your first example is the intended way. First you test and if the test says it is ok to go on then it adds to the counter.

note: You are aware that 4.5 dp-2 is beta software? The latest release is 4.0.
This just in case you run into difficulties you should at least try in the 4.0 version. This is not the case here.

regards
Bernd

Senelori
Posts: 3
Joined: Wed Mar 10, 2010 9:26 pm

Re: Strange behavior in the flow of a script

Post by Senelori » Thu Mar 11, 2010 3:58 pm

Thanks Bernd for the speed with which you have responded, and the clarity of explanation.
I'm 65 years old and do programs for many years, but I come from the old sequential programming (1970s, Assembler, Fortran and so on), so I have trouble understanding the programming events.
Perhaps too many years that I program: it's time to stop ...
But I will do good use of your suggestion: there is always to learn.

Thanks for the tip of the beta rev-dp-2: I'll be careful when I have other problems. And there will be ...

Thanks again. Regards.
Lorenzo

Post Reply