Stack stopped working

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
bd525
Posts: 80
Joined: Sun Aug 31, 2014 12:43 am

Stack stopped working

Post by bd525 » Sun Jun 27, 2021 2:17 pm

My stack was working fine, then it stopped. The stack is simple: A single card, with all handlers in that card's script. Calling any handler from a menu button or the Message Box fails. In the Message Box calling the handler setStaff, for example, results in "put setStaff" appearing in the command field, with "setStaff" showing up in the results, and the commands in the handler NOT executing.

All is not well in the card script. Twenty or thirty handlers look fine, then seemingly randomly there is this:
Code image 1.jpg
The error message is:
Code Image 2.jpg
There's nothing wrong with the contents of the line indicated as an error. Commenting out the line just shifts the error to the next, perfectly good, line of code. Commenting out the entire handler relocates the error to a perfectly good line in a later handler.

Some sort of stack corruption? I'm hoping the cause is simple, and easily rectified, but I am a relative newbie, and have no idea what's going on. Thanks.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Stack stopped working

Post by jacque » Sun Jun 27, 2021 5:16 pm

Do you have explicitVariables turned on? That's what the error message implies. If so, turn it off.

Unrelated, the parentheses around the quoted image name aren't necessary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stam
Posts: 2683
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Stack stopped working

Post by stam » Sun Jun 27, 2021 5:18 pm

Difficult to tell from your screenshot... you're only showing us a fragment of code, albeit one that contains the error...
Is variable checking switched on by chance? (with the script editor showing, ensure text in the SE is selected then click he 'Edit' menu -> options -> variable checking.

It doesn't look like you're declaring your local variables (although difficult to say for sure from your screenshot) and if variable checking is switched on it will throw errors if you haven't declared the variables first...

First of all i would recommend putting the global declarations at the top of the script, outside any handlers (that way the globals will be available for all handlers).

Then you could changing

Code: Select all

on SetStaff
    local currentLocH, divLocks, beatLocks // and whatever other local variables you use in handler
    set the fileName of... 
and see if the error goes away. If this is the source of problems then either declare all your local variables within the handler or switch off the variable checking... I prefer to always have variable checking switched on because it prevents errors from typos, but each to his own...

Hope that helps,
Stam

bd525
Posts: 80
Joined: Sun Aug 31, 2014 12:43 am

Re: Stack stopped working

Post by bd525 » Sun Jun 27, 2021 5:36 pm

The problem was indeed variable checking. Turning it off returned things to normal. I'll follow Stam's suggestions about variable declarations and their placement. FYI, I am a Director refugee, and declaring local variables there wasn't necessary (or recommended, I don't think), so that didn't occur to me as a problem. And I don't THINK declaring globals outside handlers was an option (no, not certain about that).

Thanks commenters! This is a REALLY great forum. I have posted a number of problems, and all have received timely and helpful responses.

stam
Posts: 2683
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Stack stopped working

Post by stam » Sun Jun 27, 2021 7:25 pm

bd525 wrote:
Sun Jun 27, 2021 5:36 pm
And I don't THINK declaring globals outside handlers was an option (no, not certain about that).
Yeh i remember being confused about that as well when starting out... globals need to be declared in each script (not handler) where they may be used and putting the declaration at the top means they'll be available to all subsequent handlers.
Many times a 'local' declaration outside a handler (ie a script local variable) does a similar job for all handlers in that script and may be a better choice depending on what scope you need...

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Stack stopped working

Post by bogs » Sun Jun 27, 2021 10:17 pm

stam wrote:
Sun Jun 27, 2021 7:25 pm
Many times a 'local' declaration outside a handler (ie a script local variable) does a similar job for all handlers in that script and may be a better choice depending on what scope you need...
Another good option would be a custom property, which if you need it to retain it's value even after the program closes can be accomplished, unlike any other variable.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”