Author Topic: How to debug script?  (Read 2846 times)

0 Members and 1 Guest are viewing this topic.

Offline Pedja

  • Junior Member
  • **
  • Posts: 14
  • Karma: +0/-0
How to debug script?
« 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?

PtokaX forum

How to debug script?
« on: 05 March, 2011, 22:37:40 »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
Re: How to debug script?
« Reply #1 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.
Ignorance is Bliss.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to debug script?
« Reply #2 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.
Everything could have been anything else and it would have just as much meaning.

Offline Pedja

  • Junior Member
  • **
  • Posts: 14
  • Karma: +0/-0
Re: How to debug script?
« Reply #3 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.

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
Re: How to debug script?
« Reply #4 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.
Ignorance is Bliss.

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 475
  • Karma: +209/-22
  • PtokaX developer
Re: How to debug script?
« Reply #5 on: 18 March, 2011, 10:12:01 »
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:
Quote
UDPDbg.
-------------------
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

Offline amenay

  • Member
  • ***
  • Posts: 27
  • Karma: +10/-0
Re: How to debug script?
« Reply #6 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.

PtokaX forum

Re: How to debug script?
« Reply #6 on: 19 March, 2011, 03:50:10 »