Hello Guest it is March 29, 2024, 05:09:16 AM

Author Topic: How to Exit Screen Script  (Read 1019 times)

0 Members and 1 Guest are viewing this topic.

How to Exit Screen Script
« on: March 23, 2021, 11:40:57 AM »
I have two very simple question that I cannot find answers to.

1) How do I exit a screen script. I have a simple script add to the button up script. I have an If statement that when true I want to exit the code and not continue with the lines below it.

2) I want to use mc.mcCntlSetLastError(inst, "Yadda yada")to display a message to the user and not require an acknowledgment via a message box. I have the message at the beginning of a screen script. Later in that script I have a FOR loop that I am treating as a timer. The problem is that the message will not be displayed until the end when the timer completes and the rest of the routing finishes. How can I get that message to appear as soon as it is hit in the code and not wait for completion of execution of the entire script?

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: How to Exit Screen Script
« Reply #1 on: March 24, 2021, 01:30:56 AM »
Not sure I know what you mean with #1.  Are you talking about a conditional cycle stop? 

But #2 is that the button press is a GUI event.  And the GUI cannot be updated while it is processing a GUI event.  It is the same thread of execution. 

So you have to get creative.  Maybe have a global screen script variable (defined in the screen load script), a string variable that will contain your message.  Than an addition to the PLC script that watches the string variable to become non empty and when so, , uses the string variable in a call to mcCntlSetLastError() and then finally sets the string variable to empty.

screen load script:
Code: [Select]
myMessageVar = ""

PLC script
Code: [Select]
if (myMessageVar ~= "") then
    local inst = mc.GetInstance()
    mcCntlSetLastError(inst, myMessageVar);
    myMessageVar = ""
end

Button script:
Code: [Select]
myMessageVar = "Display this now!!!"

Steve
Re: How to Exit Screen Script
« Reply #2 on: March 24, 2021, 09:18:16 AM »
Thank you for that response. The first question may be so basic that it is easy not to understand what I am asking. If I wrote a subroutine in Visual Basic and had logic that determined a need to exit the subroutine, I would use an Exit Sub command. Any node after that command would not be executed. Is there an equivalent method for exiting the code in a screen button script? Perhaps it just needs to be written as a function and stored it the screen load and called from the button script. I assume you can exit a function using "Return".

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: How to Exit Screen Script
« Reply #3 on: March 24, 2021, 01:47:57 PM »
Yes, return.  All lower case. 

if (condition == true) then
    return
end

It is a dry read, but the LUA manual may be of some use to you.  https://www.lua.org/manual/5.3/

Steve
Re: How to Exit Screen Script
« Reply #4 on: March 24, 2021, 02:43:18 PM »
I tried return but that did not work. It continued to execute instructions after that IF statement.

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: How to Exit Screen Script
« Reply #5 on: March 25, 2021, 03:49:30 AM »
Script instructions continued to execute after the return?  The return keyword has never failed me.  How about posting the entire button script.  We will find the answer. 

Steve
Re: How to Exit Screen Script
« Reply #6 on: March 25, 2021, 09:16:48 AM »
I have changed my script to use a series of if and elseif statements and eliminated the need for return. So I created the simple script below and like you said the return worked. When I get a chance I will modify my actual routine to determine if I was mistaken or if something odd is truly happening.

if 1==1 then
   wx.wxMessageBox ("Return statement next")
   return
end
wx.wxMessageBox ("Return did not work")
Re: How to Exit Screen Script
« Reply #7 on: March 25, 2021, 01:49:45 PM »
I went back to my script and sure enough return would work. Not sure what I was doing wrong before. Thank you very much for the responses!