Jump to content

Recommended Posts

  • Root Admin
Posted (edited)

Debugging Your Code
Debugging is not some weird activity programmers do...well it is but if you want to do interesting things with MDScript you have to know about it. Seeing what is inside the variables you are working with is very important to understand what you should do with them next.
Simple variables are easy to check, you just output them and see what value they have:
 

print @va;


(i usualy use 'echo' instead of 'print' , they do same thing, but print sounds easier to remember)

Best practice is to put some other value next to the one you are looking for, so that if the variable is empty, you will see that and not just an empty page not knowing if it was output or not.
 

print "V=".@va;


This will output V=something or V= if @va has no value. Better than nothing at all.

Arrays are harder to debug by just using simple output. Multidimensional arrays are even worse. Fortunately there are functions to help you see exactly what is inside a variable.

Debug Function:

debug(variable,label);


Parameters:
variable = any kind of variable simple or multidimensional array with or wihout data
label = a label to help you identify the debug output, optional (means you can use just the variable parameter)
 

debug(@va);


This will be your best friend when trying to understand what data you have in all those variables. It will generate a nice colored box with all the details you need about the internal structure of the variable you are trying to analyze

Edited by Chewett
Cleaned it all up :)
  • 6 years later...
Posted (edited)

Debug Function:
[php]mds_debug(variable,label);[/php]
 

 

The function is actually

[php]debug(variable,label);[/php]

 

Example code and output:

[php]

@va = array (1,2,3,4,5);
debug(@va,"numbers");

[/php]

 

DCKPcyF.png

Edited by Rophs

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Forum Statistics

    17.5k
    Total Topics
    182.1k
    Total Posts
  • Recently Browsing

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...