High School Dropout

All sorts of amusements and nonsense unrelated to xTalk
Post Reply
User avatar
richmond62
Posts: 5225
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

High School Dropout

Post by richmond62 »

SShot 2025-03-17 at 15.19.33.png
SShot 2025-03-17 at 15.19.33.png (30.61 KiB) Viewed 3841 times
-
Certainly NOT in the LCC 963 Dictionary: nor in the LCC 66 Dictionary.

AS that reference does NOT tell us how to use the term . . .
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3488
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: High School Dropout

Post by tperry2x »

In LiveCode, the experimental assert command was introduced as a debugging tool to help developers verify conditions within their scripts during runtime. It was primarily used for testing and debugging purposes by checking whether a given expression evaluated to true. If the condition was false, LiveCode would throw an assertion error, halting execution and making it easier to detect logic errors in code.

That's how it was supposed to work, and with Development menu > script debugger mode on, it was supposed to test if certain conditions were true. For example:

Code: Select all

on mouseDown
   put 5 into x
   assert x > 3  -- Passes, so nothing happens

   put 2 into y
   try
      assert y > 3  -- This will fail
   catch error e
      answer "Assertion failed: " & e
   end try
end mouseDown

But it does not seem to work and is not properly implemented.

I did find a way to force it to work though, by writing my own function for it.

Code: Select all

on mouseDown
   put 2 into y
   myAssert y > 3, "y should be greater than 3"
end mouseDown

command myAssert pCondition, pMessage
   if not pCondition then
      put "NO, Assertion failed: " & pMessage
   else
      put "YES, Assertion passed: " & pMessage
   end if
end myAssert
You give it an assertion to test (in the mousedown handler I'm asserting that 2 is more than 3)
If you run that, you'll see that it'll of course fail. Change the 2 to a 5 and it'll pass. It's really just meant as a way to verify something.
User avatar
OpenXTalkPaul
Posts: 2793
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: High School Dropout

Post by OpenXTalkPaul »

Extension Builder also has an 'assert' keyword that is used for testing input parameters and then can be used to report back errors to the script engine if an unsupported value was passed in to a function

It looks something like this:

Code: Select all

handler myMIDIFunction( in pPitch as integer) returns optional any
      assert that pPitch > 0 and pPitch < 128 because "the pitch parameter must be an integer between 1 and 127"
      --
end handler
if a script passes 129 as the parameter pPitch to that function, the script would throw an error with the message that follows the keyword 'because'.

I hadn't realize it was a keyword in the regular xTalk script interpreter side as well.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests