How to debug script?
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org 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.

Pedja

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?

Dessamator

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.

bastya_elvtars

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.

Pedja

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.

Dessamator

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.

PPK

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 http://forum.ptokax.org/index.php?topic=6399.0 with:
QuoteUDPDbg.
-------------------
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

amenay

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

SMF spam blocked by CleanTalk