different behaviors

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gilgml
Posts: 26
Joined: Wed Jun 16, 2021 3:35 am

different behaviors

Post by gilgml » Tue Jul 13, 2021 2:55 pm

Hi Guys,

Sometime after learning the use of specialfolderpath("resources") and sysError, i have another question please.

Code: Select all

put 4 into CardNumber
   repeat with irp = 1 to CardNumber
      put specialfolderpath("resources") into PatFil
      put "/car" & irp & ".txt" after PatFil
      if there is NOT a file PatFil then
         answer "Problem " & PatFil & " not present"
      else      
         open file PatFil
         if the sysError is not zero then
            answer "Problem opening : " & PatFil & " : " & the sysError
         else
            put 0 into NbLigInFile
            repeat until eof
               read from file PatFil for 1 line 
               put it into temp
               if temp is empty then
                  exit repeat
               else
                  add 1 to NbLigInFile
               end if
            end repeat
            answer PatFil & " " & NbLigInFile & " lignes"
         end if 
         close file PatFil
      end if
  end repeat
  
It is strange ( for the moment unavailable to my understanding ) that in certain openings, sysError is not zero.

Immediately after saving the code of the stack, the FIRST open of the file produces a 22 sysError.

All other opens of the loop ( 4 ) are ok ( sysError = 0 )

Then subsequent runs of the same code without saving it don't produce the error.

You then go to the code and introduce even a blank new line, save and the error shows up again !

I can workaround easily but need to know what i am missing, and the trick doesn't

the workaround i found is issuing

Code: Select all

 
 answer WhateverYouWant
before the loop

Any help welcome !

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: different behaviors

Post by Bernard » Tue Jul 13, 2021 6:13 pm

Just FYI (from the LC Dictionary entry on sysError)
Note: When using the sysError function to check whether a command succeeded, be sure to check the result first. The sysError reports the operating system's error report, and some operating-system commands may report a value (and therefore set the sysError) even if the command succeeded. Only if the result is not empty does the sysError indicate that the command failed.
So perhaps check result() first and only then check sysError if needed. The Note probably wouldn't be in the Dictionary if weird sysError effects hadn't tripped people up before.

Also, on a stylistic note, years ago I got into the habit of writing this:

Code: Select all

if there is NOT a file PatFil then
like this:

Code: Select all

if NOT (there is a file PatFil) then
I found there were situations where the format you used would fail i.e. the NOT was not operative. Doing it my way I never ran into a situation where the NOT was ignored. I can't see that this is related to what you are seeing, but just FYI.

gilgml
Posts: 26
Joined: Wed Jun 16, 2021 3:35 am

Re: different behaviors

Post by gilgml » Wed Jul 14, 2021 11:34 am

Thank you.
It solved the issue. :lol:
And i will use your hint to use the NOT.

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

Re: different behaviors

Post by Klaus » Wed Jul 14, 2021 12:20 pm

That is really strange!I have been using this syntax (if there is NOT a file xyz) for over 20 years now*
and never had a problem!? :shock:

*I started 1999 with the grandfather of Livecode -> MetaCard :D

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: different behaviors

Post by Bernard » Wed Jul 14, 2021 1:24 pm

Maybe the parsing has been fixed, but I started to use the
NOT ()
structure at least a decade ago.

Today I downloaded a stack from this forum. Said stack was being discussed 2011 to 2013. When I opened it today it was broken. Yet it had been in use/discussion/admiration by many of the smart people here for a couple of years. Clearly the parser at that time was more lax, and it tolerated repeat structures that were simply wrong. Opening it in a modern incarnation of the IDE and the stack stopped working (no error message, just an empty error alert).

TBH I still find the parser is too lax, e.g. sometimes not registering until executed that some extraneous character should not be on a keyword.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”