How to debug script?


29 December 2022 - PtokaX (20th anniversary edition) released...
11 April 2017 - PtokaX released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX for Windows 10 IoT released...
3 September 2015 - PtokaX released...
16 August 2015 - PtokaX released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX released...
13 April 2014 - PtokaX released...
23 March 2014 - PtokaX testing version build 454 is available.
04 March 2014 - sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

How to debug script?

Started by Pedja, 05 March, 2011, 22:37:40

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


What is proper method to debug script?

When error occurs, message shows in script console. That is ok, but I cannot find a way, how can I print to console some debug information on my own?


Well lets see , Programming 101:

There are various ways one way is to indeed run the script and see if there are any error messages, the second way is to test its commands and functions and use test variables or text as input to ensure that it returns the correct/ expected output. You can also allow a user to attempt to use the program/script and see if he experiences any errors. Third way is to give it to another scripter for him/her to attempt to find any logical or syntax errors the compiler might have missed. There are many ways to skin a cat, the best way is perhaps a mix of the above and other methods I havent stated.
Ignorance is Bliss.


With command-line Lua, print() is your friend. With PtokaX you should make the hub bot send it somewhere, like as a private message to you. And if you are stuck with no syntax errors but not having the desired result, it is wise to make the program say something after i. e. every step of a more complex function, like the return value should be tht, or anything you wanna know in that particular context.
Everything could have been anything else and it would have just as much meaning.


Thanks people, I already tried what you suggested.

I was just wondering if there is something nice and simple like print() that would show up in Ptokax script console.


Well I personally found that the best way(for me) to debug a script, is to use SendToAll("script stuff"), another method would be to place it within code that you suspect has errors or perhaps output variables that might have issues.
The best approach would be an IDE(Integrated Development Environment) for lua, which you could set watches for certain variables and use trace into and other functions. Perhaps something like LuaEdit would be helpful, although you'll have issues with Ptokax core functions, which are not part of the "pure" lua language.
Ignorance is Bliss.


Quote from: Pedja on 16 March, 2011, 13:11:57
I was just wondering if there is something nice and simple like print() that would show up in Ptokax script console.
It is not exactly to PtokaX console, but you can use UDP debug with:
Reg(sIp, nPort, bAllData)   - Register to receiving data to PtokaX UDP Debug receiver, bAllData false means to receive only data from this script. Return nil when failed or true when success.
Unreg()            - Remove from receiving data.
Send(sData)         - Send data to udp debug. If script is registered then only to this reg, else to all. Return nil when failed or true when success.
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall


You might like this. An older version is on the boards here's what I'm working with currently. Read the howto.

SMF spam blocked by CleanTalk