Hello Guest it is April 19, 2024, 08:03:50 AM

Author Topic: lua error or is it  (Read 2203 times)

0 Members and 1 Guest are viewing this topic.

Offline mark4

*
  •  167 167
    • View Profile
lua error or is it
« on: September 12, 2017, 11:14:49 PM »
hello i was scripting and ran debug on plc script thats the first half then ran debug again thats the second half error on line 3. so i went back to basics straight install opened default mill profile went into edit ran the debug on a virgin plc script twice and this is what happened

Output: "C:\Users\Mark\AppData\Local\Temp\le1AF.mcc"
Waiting for client connection...
Client connected ok.
At Breakpoint line: 1 file: C:\Users\Mark\AppData\Local\Temp\le1AF.mcs
mcLua ERROR: Lua: Error while running chunk
[string "C:\Users\Mark\AppData\Local\Temp\le1AF.mcs"]:3: attempt to perform arithmetic on global 'testcount' (a nil value)
stack traceback:
   [string "C:\Users\Mark\AppData\Local\Temp\le1AF.mcs"]:3: in main chunk

so the question is it really an error or does the program just think it is. build 3233
thanks

Debug session finished.
Re: lua error or is it
« Reply #1 on: September 13, 2017, 01:04:39 AM »
Hi,
certainly LUA considers an error to have occurred, whether that makes sense is another matter.
Does your code use the variable 'testcount'?

My reading of the error diagnostic is that testcount is addressed when it has not been declared or initalised
and therefore a 'nil value'.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline mark4

*
  •  167 167
    • View Profile
Re: lua error or is it
« Reply #2 on: September 13, 2017, 06:40:37 PM »
hi my script additions which are basic still trying to get a handle on lua but getting better. had fun this morning lua error missing a comma after an end thought they weren't needed however in the right context they are. i believe the problem is when you run debug on plc script twice as it doesnt error the first time. to check my work i uninstalled mach4 3233 and reinstalled just mach no plug ins no machine computer only and no changes to any script the error is consistent i dont know if it is a problem or if its just a nuesence.
mark
Re: lua error or is it
« Reply #3 on: September 14, 2017, 06:53:42 AM »
Hi,
I found testcount in the PLC script:
Code: [Select]
testcount = testcount + 1Reading the remaining code the script uses testcount variable to do certain setup tasks on the first pass of the PLC script
and not subsequent passes.
The fact that it passes the first time its run without error suggests that all is well. On the second pass however testcount has mysteriously
been corrupted and is now considered to be a nil value. What gives? Is there code in your PLC script which overwrites or otherwise corrupts
testcount? As you can tell LUA is still new and mysterious to me as well!

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: lua error or is it
« Reply #4 on: September 15, 2017, 10:32:51 PM »
Guys, you really can't "debug" the PLC script like a macro.  Why?  Because the PLC script is only part of a larger script.  If you do Operator->Lau Script, you will see ALL of the screen scripts merged together.  What you will find is that testcount is declared in the screen load script. 

The reason all of the various scripts are merged together is so that each script can access these global variables.  The scripts are all merged to form one "LUA chunk". 

So to debug the PLC script, one can do Operator->Lau Script, copy the contents, and then past the whole script into the mcLuaEditor.  Then, at the bottom, insert a line that calls the PLC script function. 

Steve

Offline mark4

*
  •  167 167
    • View Profile
Re: lua error or is it
« Reply #5 on: September 17, 2017, 08:07:52 PM »
thanks for the reply so in a nutshell basic lua plc debug will call an error where none exists because it doesnt have the whole picture. for me just good to know as my lua is iffy and i count on debug to save me from myself.
m