Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-28-2009, 09:50 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Debugger

Well after doing some work in PowerBuilder (I know a lot of IDE's have that kind of functionality as well), I got to use the debugger and breakpoints and found them quite useful.

So I created a debugger class that you can attach to any of your scripts.

PHP Code:
/*
   Core Debugger Functions: 
   
     Avoid overwriting these functions in your scripts.
   
     - onInitializeDebugger()
     - onCreateDebuggerGUI(title)
     - onChangeDebuggerScope(obj)
     - onDebuggerCall(obj)
     - onResumeDebuggingCode(obj)
     - onResumingCode()
   
   Debugging Functions:
   
     Call these in your scripts to use the debugger.
   
     - debug_breakPoint(temp.time)
     - debug_updateVariables(temp.scope)
   
*/
//#CLIENTSIDE

function onCreated() {
  
// Control Debug Access
  
temp.debuggers = {
    
"fowlplay4"
  
};
  if (
player.account in temp.debuggers) {
    
onInitializeDebugger();
  }
}

function 
onInitializeDebugger() {
  
// Initialize Debugger GUI
  
onCreateDebuggerGUI(this.name);
}

function 
onCreateDebuggerGUI(title) {
  
// Creates Simple Debugger GUI
  
new GuiWindowCtrl("Debugger_" title) {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "173,262";
    
canmove true;
    
canresize false;
    
closequery false;
    
canminimize canmaximize false;
    
destroyonhide true;
    
visible true;
    
text "Debugging:" SPC title;
    
screenwidth 200;
    
7;

    new 
GuiTextCtrl("Debugger_" title "Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Variables";
      
width 46;
      
11;
    }
    new 
GuiScrollCtrl("Debugger_" title "_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 192;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 163;
      
5;
      
19;
      new 
GuiTextListCtrl("Debugger_" title "_List") {
        
profile GuiBlueTextListProfile;
        
height 32;
        
horizsizing "width";
        
width 159;
        
temp.varlist this;
      }
    }
    new 
GuiTextEditCtrl("Debugger_" title "_Scope") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 126;
      
42;
      
214;
      
text "this.";
      
this.varslist temp.varlist;
      
thiso.catchevent(name"onAction""onChangeDebuggerScope");
      
hint "Press enter to change debugger's variable scope.";
    }
    new 
GuiTextCtrl("Debugger_" title "_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Scope";
      
width 31;
      
7;
      
213;
    }
    new 
GuiTextCtrl("Debugger_" title "_Text3") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Call";
      
width 17;
      
11;
      
238;
    }
    new 
GuiTextEditCtrl("Debugger_" title "_Call") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 126;
      
42;
      
239;
      
thiso.catchevent(name"onAction""onDebuggerCall");
      
hint "Press enter to call a certain function in the script.";
    }
  }
  
// Populate Variable List
  
debug_updateVariables();
}

function 
onChangeDebuggerScope(obj) {
  
// Clear List
  
temp.list = obj.varslist;
  
temp.list.clearrows();
  
// Determine Scope
  
temp.scope obj.text;
  
temp.scope temp.scope.ends(".") ? temp.scope : (temp.scope ".");
  
// Locate Variables
  
temp.variablez getstringkeys(temp.scope);
  
// Determine Functions
  
temp.functionz this.getfunctions();
  
// List Variables
  
for (temp.var: variablez) {
    
// Filter out Functions
    
if (temp.var in temp.functionz) continue;
    
// Get Value of Variable
    
temp.value makevar(temp.scope temp.var);
    
// Add Row to Variable List
    
temp.data temp.scope temp.var @ ": " temp.value;
    
temp.row = list.addrow(0temp.data);
    
temp.row.hint temp.value;
  }
}

function 
onDebuggerCall(obj) {
  
// Determine Call
  
temp.call obj.text;
  
// Call Object
  
if (call.starts("on")) this.trigger(call.substring(2), "");
  else 
this.(@call)();
}

function 
onResumeDebuggingCode(obj) {
  
// Decrease Window Size
  
with (makevar("Debugger_" thiso.name)) {
    
height -= 32;
  }
  
// Destroy Button
  
obj.destroy();
  
// Resume Code
  
this.trigger("onResumingCode""");
}

/*
   Halts the script and places the resume button on the
   debugger.
   
   temp.time - The length in seconds to halt script for.
               If unspecified, defaults to 24 hours.
*/

function debug_breakPoint(temp.time) {
  
// Check for Debugger Window
  
if (!isObject("Debugger_" this.name)) return;
  
// Create Resume Button 
  
with (makevar("Debugger_" this.name)) {
    if (!
isObject("Debugger_" thiso.name "_Resume")) {
      
height += 32;
      new 
GuiButtonCtrl("Debugger_" thiso.name "_Resume") {
        
4;
        
239 22;
        
width 164;
        
text "Resume Code";
        
profile "GuiBlueButtonProfile";
        
thiso.catchevent(name"onAction""onResumeDebuggingCode");
      }
    }
  }
  
// Update Variable List based on Scope
  
debug_updateVariables();
  
// Begin Wait
  
waitfor(this"onResumingCode", (temp.time temp.time 3600 24));
}

/*
   Updates the variable list.
   
   temp.scope - If specified it overwrites the scope in
                the text box, and updates accordingly.
*/

function debug_updateVariables(temp.scope) {
  
// Determine Scope Object
  
temp.obj_scope makevar("Debugger_" this.name "_Scope");
  
// Update Scope Text if neccesary
  
temp.obj_scope.text temp.scope temp.scope temp.obj_scope.text;
  
// Update Variable List
  
onChangeDebuggerScope(temp.obj_scope);

It's very simple to use, adjust the account access array in the created event of the debugger class so you have access then add the following to the top of your script:

PHP Code:
function onCreated() {
  
// Assuming you named the class debugger
  
join("debugger");

You can join it on the client-side as well but depending on the method that you use you'll have to update the script twice or reconnect to get the debugger to appear.

If you joined it on the server-side you have to use the following code to remove it:

PHP Code:
function onCreated() {
  
join("debugger");
  
leave("debugger");

Here's some example usage of what the debugger can do so far:

PHP Code:
function onCreated() {
  
// Assuming you named the class debugger
  
join("debugger");
}

//#CLIENTSIDE
function onCreated() {
  
// Call Example Function
  
someCrazyScript();
}

function 
someCrazyScript() {
  
// Example Code
  
this.something 1;
  
this.lolol true;
  
// Pause Script for Debugger
  
debug_breakPoint();
  
// Example Code Continued
  
this.something 2;
  
// Update Variable List for Debugger
  
debug_updateVariables("this.");

At the moment it's quite simple but I may look into adding/improving features like:

- Serverside Functionality
- Editing Values in Debugger
- Improved GUI
- External Windows (when the v6 Beta comes)

Here's an image of it in action, I inserted a break point in the script when the player reaches the peak of the jump in my gravity script.
Attached Thumbnails
Click image for larger version

Name:	graal_1259436924.png
Views:	833
Size:	24.2 KB
ID:	49929  
__________________
Quote:

Last edited by fowlplay4; 11-29-2009 at 01:00 AM..
Reply With Quote
  #2  
Old 11-28-2009, 09:52 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Ha, that's pretty cool. Nice work.
__________________
Reply With Quote
  #3  
Old 11-28-2009, 09:54 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Wow!! Great work!

Stickyy
Reply With Quote
  #4  
Old 11-29-2009, 12:57 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Thanks.

Due to this bug:
http://forums.graalonline.com/forums...00#post1541000

To remove the debugger class from the weapon script if you joined it on the server-side do the following:

PHP Code:
function onCreated() {
  
join("debugger");
  
leave("debugger");

__________________
Quote:
Reply With Quote
  #5  
Old 11-29-2009, 03:56 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
This needs to be stickied.
__________________
Reply With Quote
  #6  
Old 11-29-2009, 04:27 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Nice work

There is one thing that bugs me though, and I know this is probably a personal-preference thing, is the way you name your functions. I'd have thought it'd be logical to reserve the prefix "on" for events, which is how your debugger seems to work aswell, but you seem to be using them for standard functions.

Of course, it may seem like I'm nitpicking. Either way, it's a great system and I'll definitely be using it.

rep++
Reply With Quote
  #7  
Old 11-29-2009, 05:02 PM
Soala Soala is offline
Ideas on Fire
Soala's Avatar
Join Date: Jun 2007
Location: In my head
Posts: 3,208
Soala is a jewel in the roughSoala is a jewel in the rough
Great work you've done here. rep++
Reply With Quote
  #8  
Old 11-29-2009, 08:18 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Codein View Post
Nice work

There is one thing that bugs me though, and I know this is probably a personal-preference thing, is the way you name your functions. I'd have thought it'd be logical to reserve the prefix "on" for events, which is how your debugger seems to work aswell, but you seem to be using them for standard functions.

Of course, it may seem like I'm nitpicking. Either way, it's a great system and I'll definitely be using it.

rep++
I enjoy the ability of being to trigger, and scheduling the functions I make so that's why I name them the way I do.
__________________
Quote:
Reply With Quote
  #9  
Old 11-29-2009, 08:50 PM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
Nice, reminds me of around 4 years ago when Stefan said "online debugging was planned" but then I never heard anything else from it.
Reply With Quote
  #10  
Old 11-29-2009, 09:06 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by fowlplay4 View Post
I enjoy the ability of being to trigger, and scheduling the functions I make so that's why I name them the way I do.
Understandable.
Reply With Quote
  #11  
Old 12-08-2009, 01:59 PM
Samposse Samposse is offline
Chopa Shopa !
Samposse's Avatar
Join Date: Nov 2008
Location: Norway
Posts: 87
Samposse is an unknown quantity at this point
Send a message via AIM to Samposse Send a message via MSN to Samposse
Nice like it
__________________
Delitto :3

A
SERVER
UNDER
CONSTRUCTION !

feel free to ask me about delitto
Reply With Quote
  #12  
Old 02-28-2010, 07:33 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
yeah, makes me sad that I still make my own showtext box in the corner to do that. ..

.. Geez, that's exactly the kind of script I was working on too, the one in the screenshot LOL
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #13  
Old 02-28-2010, 03:40 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
is u workin on a platforming project :>?
__________________
Reply With Quote
  #14  
Old 02-28-2010, 07:49 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Crono View Post
is u workin on a platforming project :>?
Looks more like a gravity event.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #15  
Old 02-28-2010, 08:14 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by coreys View Post
Looks more like a gravity event.
Yep, but that script is now being used in Zodiac's other gravity event now.
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.