Hello Guest it is April 23, 2024, 10:50:53 AM

Author Topic: wx.MessageBox wait  (Read 640 times)

0 Members and 1 Guest are viewing this topic.

wx.MessageBox wait
« on: December 20, 2021, 01:40:30 PM »
I am so new to LUA I cannot figure this out. I have added three buttons to my screen set that move the machine to positions such as the tool change position. My issue is that I want the message box to pop up after the machine has finished moving into position. Currently when I select the button(s) the message box comes up before it even starts moving. I have tried putting it after the function() in the button left upp script, and all around within the function itself in the screen load script. I get the same outcome, or no outcome at all. I don't know if there is a wait or yield that can go with the message box or if I need a whole script of some junk to make that happen exactly how I expect it to?
Any advise would be super appreciated.

Thanks in advance!
Re: wx.MessageBox wait
« Reply #1 on: December 21, 2021, 06:27:46 AM »
You need to use a coroutine. Check out the Ref All button on the default Mach4 screens it uses one there.

This goes in your button script
wait = coroutine.create(testfunction)

Function goes in the screen load script - Note the coroutine.yield() after the Mdi execute
function testfunction()
     local inst = mc.mcGetInstance()
    mc.mcCntlMdiExecute(inst, "G0 X1")
    coroutine.yield()
    wx.wxMessageBox("Hello")
end

In the default mach screens there is some lua script in the PLC that will resume the couroutine called 'wait' if it is yielded and the Mach state is idle.  This code should already be in your screen...
Re: wx.MessageBox wait
« Reply #2 on: December 21, 2021, 06:33:08 AM »
Swifty, thank you for your reply. I figured it would be something like that, I just didn't have a clue where to start.
I will definetly try this out this evening and report back with the outcome.
Again, thanks for your reply! Sometimes we just need a little direction.

Have yourself a great Tuesday!
Re: wx.MessageBox wait
« Reply #3 on: December 22, 2021, 06:27:16 AM »
Swifty, the coroutine worked perfectly!!
I was so excited. Enjoy the small victories, right?

Thank you very much!
This will be usefull in the future as I move ever closer to the machine I wanted.