View Single Post
  #12  
Old 10-07-2006, 01:33 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Ok. I have made an example for the second lesson - a practical based lesson. 400 lines of code but not all mine (<3 Jamilla/Novo) and comments/styling help to fill up that number. This also forced me to use 2 posts . No ripping off my tripple post

PHP Code:
/* Lesson 2 : Practical */
//#CLIENTSIDE
function onCreated()
  
addGUIControls();

function 
onWeaponFired()
  
showLesson();
  
public function 
showLesson()
{
  new 
GuiWindowCtrl("Lesson2Window")
  {
    
profile       "GuiBlueWindowProfile";
    
extent        "450 300";
    
position      "5 5";
    
text          "Lesson 2 : Practical Lesson. By Twinny";
    
destroyonhide true;
    
canmaximize   false;
    
canresize     false;
    
    new 
GuiTextCtrl("Lesson2Title")
    {
      
profile          "GuiBlueTextProfile";
      
position         "10 25";
      
profile.fontsize 40;
      
text "Practical Lesson on Objects";
    }
    
    new 
GuiScrollCtrl("Lesson2Scroll")
    {
      
profile    "GuiBlueScrollProfile";
      
position   "15 75";
      
extent     "420 140";
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
visible    true;
      
canmove    true;
    
      new 
GuiMLTextCtrl("Lesson2Body")
      {
        
profile  "GuiBlueMLTextProfile";
        
position "5 5";
        
extent   "390 110";
      }
    }
    new 
GuiButtonCtrl("Lesson2Prac1")
    {
      
profile  "GuiBlueButtonProfile";
      
position "15 220";
      
extent   "420 30";
      
text     "Practical Lesson 1";
    }
    new 
GuiButtonCtrl("Lesson2Prac2")
    {
      
profile  "GuiBlueButtonProfile";
      
position "15 255";
      
extent   "420 30";
      
text     "Practical Lesson 2";
    }
          
  }
  
GraalControl.addControl(Lesson2Window);
  
setLesson();
}

function 
setLesson()
{
  
Lesson2Body.setText(
  
"Below are two practical lessons. The first prac lesson is a
  basic lesson. It shows all the functions, objects and variables
  contained within an object of your choosing." 
NL "" NL
  
  
"The second lesson is a bit more advanced. The second lesson 
  shows the interconnected ness of objects within graal.
  Objects and arrays can be expanded. The functions and variables
  are present just to show you what is in each object you find." 
NL "" NL
  
  
"Next lesson will involve some questions based on objects as well 
  as some examples and tasks. It is hoped by then you will have a 
  basic understanding of objects. All credit for the practical lessons
  should go to Jamilla/Novo. I modified the first practical lesson
  a fair bit but the second one is generally the same as his
  original work. Ask the lesson provider if you wish to receive
  the practical lesson's code." 
NL "" NL
  
  
"As always if this lesson was confusing as hell - just mail me at
  [email protected]"
  
);
}

function 
Lesson2Prac1.onAction()
  
showPrac1();

function 
Lesson2Prac2.onAction()
{
  if (
this.on
    
turnoff();
  else
    
turnon();
}
  
/* And now for the practical lessons. Once more - credit
goes to Jamilla/Novo */

/* Practical Lesson 1 */
/* Modified quite a bit */
function showPrac1()
{
  new 
GuiWindowCtrl("L2P1")
  {
    
profile  "GuiBlueWindowProfile";
    
position "5 5";
    
extent   "450 300";
    
text     "Lesson 2 : Practical 1. By Twinny";
    
destroyonhide true;
    
canmaximize   false;
    
canresize     false;
  
    new 
GuiTextCtrl("L2Prac1Title")
    {
      
profile  "GuiBlueTextProfile";
      
profile.fontsize 22;
      
position "90 25";
      
text     "Select your object than parse";
    }
    
    new 
GuiPopUpMenuCtrl("L2Prac1PopUp")
    {
      
profile "GuiBluePopUpMenuProfile"// -_-
      
position "10 55";
      
extent   "280 25";
    }
    new 
GuiButtonCtrl("L2Prac1B1")
    {
      
profile  "GuiBlueButtonProfile";
      
position "300 55";
      
extent   "140 25";
      
text     "Parse";
    }
    new 
GuiScrollCtrl("L2Prac1Scroll")
    {
      
profile    "GuiBlueScrollProfile";
      
position   "15 90";
      
extent     "420 200";
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
visible    true;
      
canmove    true;
    
      new 
GuiMLTextCtrl("L2Prac1Dump")
      {
        
profile  "GuiBlueMLTextProfile";
        
position "5 5";
        
extent   "390 180";
      }
    }
  }
  
GraalControl.addControl(L2P1);
  
setObjects();
}

function 
setObjects()
{
  
temp.objs = {"Player","Level""Allplayers",
  
"Allplayers[1]""GuiControl","Weapon"};
  for (
tp temp.objs)
    
L2Prac1PopUp.addrow(1,tp);
}

function 
L2Prac1B1.onAction()
{
  
L2Prac1Dump.text "";
  if (
L2Prac1PopUp.text == "Player")
    
var_dump(player);
  else if (
L2Prac1PopUp.text == "Level")
    
var_dump(player.level);
  else if (
L2Prac1PopUp.text == "Allplayers")
    
var_dump(allplayers);
  else if (
L2Prac1PopUp.text == "Allplayers[1]")
    
var_dump(allplayers[1]);
  else if (
L2Prac1PopUp.text == "GuiControl")
    
var_dump(new GuiControl(Test));
  else if (
L2Prac1PopUp.text == "Weapon")
    
var_dump(player.weapon);  
}

function 
var_dumpobj )
{
  if ( 
obj.type() in {0,1,3} )
  {
    
L2Prac1Dump.addtextobj SPC "=" SPC ParseValuemakevar(obj) ) @";" NL "",);
    return 
true;
  }
  
L2Prac1Dump.addtext"new" SPC obj.objectType() @"(\""obj.name @"\"){" NL "",);
  
temp.functions obj.getFunctions();
  for ( 
temp.functemp.functions )
    
L2Prac1Dump.addtext("  function" SPC temp.func@"()" NL "",1);
  
temp.vars obj.getVarNames();
  for (
temp.varitemp.vars )
    
L2Prac1Dump.addtext"  "temp.vari SPC "=" SPC ParseValueobj.(@ temp.vari ) ) @";" NL "",1);
  
L2Prac1Dump.addtext"};" NL "",);
}

function 
ParseValueobj )
{
  switch ( 
obj.type() )
  {
    case 
"0":
      return 
obj;
    case 
"1":
      return 
"\""obj @"\"";
    case 
"2":
      return 
obj.objectType();
    case 
"3":
      
temp.arr "{";
      
temp.0;
      for ( 
temp.subobjobj )
      {
        
temp.arr @= ParseValuetemp.subobj );
        if ( 
temp.!= obj.size() - 1)
          
temp.arr @= ", ";
        
temp.++;
      }
      
temp.arr @= "}";
      return 
temp.arr;
    break;
  }

Second practical example found below.
Reply With Quote