PtokaX forum

Development Section => Your Developing Problems => Topic started by: Pedja on 05 March, 2011, 22:37:40

Title: How to debug script?
Post by: Pedja on 05 March, 2011, 22:37:40
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?
Title: Re: How to debug script?
Post by: Dessamator on 07 March, 2011, 11:18:23
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.
Title: Re: How to debug script?
Post by: bastya_elvtars on 13 March, 2011, 00:57:02
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.
Title: Re: How to debug script?
Post by: Pedja on 16 March, 2011, 13:11:57
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.
Title: Re: How to debug script?
Post by: Dessamator on 18 March, 2011, 09:28:12
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.
Title: Re: How to debug script?
Post by: PPK on 18 March, 2011, 10:12:01
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.
Title: Re: How to debug script?
Post by: amenay on 19 March, 2011, 03:50:10
You might like this. An older version is on the boards somewhere...so here's what I'm working with currently. Read the howto.