DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • August 17, 2017, 08:36:41 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: How to: WritingYour First Module  (Read 2195 times)
0 Members and 1 Guest are viewing this topic.
Rhea
Guest
« on: January 15, 2007, 06:07:14 PM »

while installing the module builder I get this fatal error;


Parse error: syntax error, unexpected '{' in /home/sassydra/public_html/crazyrealms/lotgd-1.1.0/modules/questing.php on line 75

but when I take the { out it gives me this fatal error also...


Parse error: syntax error, unexpected T_CASE in /home/sassydra/public_html/crazyrealms/lotgd-1.1.0/modules/questing.php on line 76
 
I also get the same errors in my lotgd-1.0.6 server.

Could someone help me with this? Thanks Smiley
Logged
SaucyWench
Mod God
*****
Offline Offline

Posts: 2238


I'm a good girl.


View Profile WWW
« Reply #1 on: January 16, 2007, 02:52:11 AM »

"unexpected {" does not mean that the { is wrong, it means it was expecting something else. Often it should have been a ( and so on, or you might find that the line BEFORE is the problem, with someone having forgotten a trailing semicolon on the end of the line. Either way you won't solve it by deleting the brace. Someone a bit code savvy needs to have a look at the whole file. Or Rhea, if you have your text editor installed, turn on the brace highlighting and see if you can find where there's a missing or incorrect ) or } somewhere.
Logged

SaucyWench
Owner of GemDust.com and Darton City proudly hosted by LunarPages
Rhea
Guest
« Reply #2 on: January 16, 2007, 07:12:45 AM »

<?php
$quests = array( "stolenitem" => array("Description"=>"During the night something snuck into my home
                                                       and removed a very valuable item from within.
                                          find that creature and destroy it and I shall
                                          reward you.",
                                       "Reward"=>'$session["user"]["gold"]+=900;output("Your pockets feel heavier, you have recieved 900 gold.");',
                                       "Type"=>"creature",
                                       "Name"=>"stolenitem"
                                      ),
                 "gosomeplace"=> array("Description"=>"I see that you like to travel go to $(TownName)
                                            and I shall reward you.",
                                       "Reward"=>'$session["user"]["gems"]++;output("Your pockets feel heavier, you have recieved 1 gem.");',
                                       "Type"=>"town",
                                       "Name"=>"gosomeplace"
                                      )
               );

function questing_getmoduleinfo(){
  $info = array(
    "name"=>"Configurable Questing Module",   // Name to display to the admin
    "version"=>"1.0",                         // Version number of the module
    "author"=>"Jeremy Darling",               // Your name
    "category"=>"Questing",                   // Category to list module under when installed
    "download"=>"http://www.dragonprime.net/",// Download location for module
    "prefs"=>array(
                   "Questing module settings,title",
                   "CurrentQuest"=>"Current user quest|",
                   "VillageName"=>"Village to travel to|"
                  )
  );
  return $info;
}

function questing_install(){
  if (!is_module_installed("cities")) {
    output("This module requires the Multiple Cities module to be installed.");
    return false;
  }

  module_addhook("battle-victory");
  module_addhook("village");
  module_addeventhook("forest", "return 100;");
  return true;
}

function questing_uninstall(){
  return true;
}

function questing_CompletedQuest()
{
  output("From no where the Quest Master appears in front of you.  \"You have done
          as I asked.  Now here is your reward\".");
}

function questing_HandleVitory(){
  $idropped  = e_rand(1, 100);
  global $session;
  if (($idropped < 50) && ($idropped > 20))
  {
    questing_CompletedQuest();
    eval($quest["Reward"]);
    output("`n");
    set_module_setting("VillageName", "");
    set_module_setting("CurrentQuest", "");
  }
}

function questing_dohook($hookname,$args){
  global $session;
  $questname = get_module_setting("CurrentQuest");
  if ($questname <> '')
    $quest = $quests[$questname];
    $townname = get_module_setting("VillageName");
Error here:    swtich($hookname){
      case "village":
        if ($session['user']['location'] == $townname){
          questing_CompletedQuest();
          eval($quest["Reward"]);
          output("`n");
          set_module_setting("VillageName", "");
          set_module_setting("CurrentQuest", "");
        }
      break;
      case "battle-victory":
        questing_HandleVitory();
      break;
      default:
        // code for an undefined hoook goes here
      break;
    }
  }
  return $args;
}

function questing_runevent($type){
  $op = httpget("op");
  swtich($type){
    case "forest":
    default:
      if ($op<>"")
      {
        questing_HandleEventOp($op);
      }
      else
      {
         // code to handle hook goes here
       output("You stumble upon a small hut in the middle of no where.  From within
              the hut a small elf appears.  \"I am the quest master\" he exclaims.
              \"If you are brave and willing I will send you upon a quest and
             upon its completetion will reward you\".");
       addnav("Ask about a Quest","forest.php?op=askforquest");
       addnav("Run away", "forest.php?op=chicken");
       $session['user']['specialinc'] = "module:questing";
     }
    break;
  }
  output("`0");
  return $args;
}

function questing_GetRandomQuest(){
  $questnum = e_rand(1, count($quests));
  reset($quests);
  if ($questnum>1){
    for($i=1;$i<$questnum;$i++){
      next($quests);
    }
  }
  return current($quests);
}

function questing_GetRandomCity()
{
  $vloc = array();
  $vname = getsetting("villagename", LOCATION_FIELDS);
  $vloc[$vname] = "village";
  $vloc = modulehook("validlocation", $vloc);
  $cityindex = e_rand(1, count($vloc));
  reset($vloc);
  if ($cityindex>1){
    for($i=1;$i<$cityindex;$i++){
      next($vloc);
    }
  }
  return key($vloc);
}

function questing_run(){
}

function questing_HandleEventOp($op){
  global $session;

  $op = httpget("op");
  switch($op){
    case "askforquest":
      if (get_module_setting("CurrentQuest") <> '')
      {
        output("Why is it you bother me once again when you still haven't managed ");
        output("to do the simple task I put before you.  Now be gone, until you have ");
        output("completed what I asked.");
      $session['user']['specialinc']="";
      }
      else
      {
        $quest = questing_GetRandomQuest();
        $townname = questing_GetRandomCity();
        $quest['Description'] = str_replace("$(TownName)", $townname, $quest['Description']);
        output($quest['Description']);
        set_module_setting("CurrentQuest", $quest['Name']);
        set_module_setting("VillageName", $townname);
      $session['user']['specialinc']="";
      }
    break;
    case "chicken":
      output("Deciding that this fellow looks a bit too much like the madman killer
             you see on TV every night you quickly hit the rewind button back to
           the forest.");
      $session['user']['specialinc'] = "";
    break;
  }
}
?>



i put an "Error here" to make it easier for someone to pinpoint the error...
Thank you Saucy Smiley
Logged
Sichae
iMod God
SVN Users
Mod God
*
Offline Offline

Posts: 3458


If ya didn't get it by now... you're hopeless...


View Profile WWW
« Reply #3 on: January 16, 2007, 07:23:17 AM »

switch is spelled wrong.
Logged

If you didn't understand anything in the above post, don't try to attempt anything suggested.

Rhea
Guest
« Reply #4 on: January 16, 2007, 07:53:52 AM »

<?php
$quests = array( "stolenitem" => array("Description"=>"During the night something snuck into my home
                                                       and removed a very valuable item from within.
                                          find that creature and destroy it and I shall
                                          reward you.",
                                       "Reward"=>'$session["user"]["gold"]+=900;output("Your pockets feel heavier, you have recieved 900 gold.");',
                                       "Type"=>"creature",
                                       "Name"=>"stolenitem"
                                      ),
                 "gosomeplace"=> array("Description"=>"I see that you like to travel go to $(TownName)
                                            and I shall reward you.",
                                       "Reward"=>'$session["user"]["gems"]++;output("Your pockets feel heavier, you have recieved 1 gem.");',
                                       "Type"=>"town",
                                       "Name"=>"gosomeplace"
                                      )
               );

function questing_getmoduleinfo(){
  $info = array(
    "name"=>"Configurable Questing Module",   // Name to display to the admin
    "version"=>"1.0",                         // Version number of the module
    "author"=>"Jeremy Darling",               // Your name
    "category"=>"Questing",                   // Category to list module under when installed
    "download"=>"http://www.dragonprime.net/",// Download location for module
    "prefs"=>array(
                   "Questing module settings,title",
                   "CurrentQuest"=>"Current user quest|",
                   "VillageName"=>"Village to travel to|"
                  )
  );
  return $info;
}

function questing_install(){
  if (!is_module_installed("cities")) {
    output("This module requires the Multiple Cities module to be installed.");
    return false;
  }

  module_addhook("battle-victory");
  module_addhook("village");
  module_addeventhook("forest", "return 100;");
  return true;
}

function questing_uninstall(){
  return true;
}

function questing_CompletedQuest()
{
  output("From no where the Quest Master appears in front of you.  \"You have done
          as I asked.  Now here is your reward\".");
}

function questing_HandleVitory(){
  $idropped  = e_rand(1, 100);
  global $session;
  if (($idropped < 50) && ($idropped > 20))
  {
    questing_CompletedQuest();
    eval($quest["Reward"]);
    output("`n");
    set_module_setting("VillageName", "");
    set_module_setting("CurrentQuest", "");
  }
}

function questing_dohook($hookname,$args){
  global $session;
  $questname = get_module_setting("CurrentQuest");
  if ($questname <> '')
    $quest = $quests[$questname];
    $townname = get_module_setting("VillageName");
   swtich($hookname){
      case "village":
        if ($session['user']['location'] == $townname){
          questing_CompletedQuest();
          eval($quest["Reward"]);
          output("`n");
          set_module_setting("VillageName", "");
          set_module_setting("CurrentQuest", "");
        }
      break;
      case "battle-victory":
        questing_HandleVitory();
      break;
      default:
        // code for an undefined hoook goes here
      break;
    }
  }
  return $args;
}  NOW ERROR HERE:

function questing_runevent($type){
  $op = httpget("op");
  swtich($type){
    case "forest":
    default:
      if ($op<>"")
      {
        questing_HandleEventOp($op);
      }
      else
      {
         // code to handle hook goes here
       output("You stumble upon a small hut in the middle of no where.  From within
              the hut a small elf appears.  \"I am the quest master\" he exclaims.
              \"If you are brave and willing I will send you upon a quest and
             upon its completetion will reward you\".");
       addnav("Ask about a Quest","forest.php?op=askforquest");
       addnav("Run away", "forest.php?op=chicken");
       $session['user']['specialinc'] = "module:questing";
     }
    break;
  }
  output("`0");
  return $args;
}

function questing_GetRandomQuest(){
  $questnum = e_rand(1, count($quests));
  reset($quests);
  if ($questnum>1){
    for($i=1;$i<$questnum;$i++){
      next($quests);
    }
  }
  return current($quests);
}

function questing_GetRandomCity()
{
  $vloc = array();
  $vname = getsetting("villagename", LOCATION_FIELDS);
  $vloc[$vname] = "village";
  $vloc = modulehook("validlocation", $vloc);
  $cityindex = e_rand(1, count($vloc));
  reset($vloc);
  if ($cityindex>1){
    for($i=1;$i<$cityindex;$i++){
      next($vloc);
    }
  }
  return key($vloc);
}

function questing_run(){
}

function questing_HandleEventOp($op){
  global $session;

  $op = httpget("op");
  switch($op){
    case "askforquest":
      if (get_module_setting("CurrentQuest") <> '')
      {
        output("Why is it you bother me once again when you still haven't managed ");
        output("to do the simple task I put before you.  Now be gone, until you have ");
        output("completed what I asked.");
      $session['user']['specialinc']="";
      }
      else
      {
        $quest = questing_GetRandomQuest();
        $townname = questing_GetRandomCity();
        $quest['Description'] = str_replace("$(TownName)", $townname, $quest['Description']);
        output($quest['Description']);
        set_module_setting("CurrentQuest", $quest['Name']);
        set_module_setting("VillageName", $townname);
      $session['user']['specialinc']="";
      }
    break;
    case "chicken":
      output("Deciding that this fellow looks a bit too much like the madman killer
             you see on TV every night you quickly hit the rewind button back to
           the forest.");
      $session['user']['specialinc'] = "";
    break;
  }
}
?>



i put an "Error here" to make it easier for someone to pinpoint the error...
Thank you Saucy Smiley


I ran a spell check and fixed the few misspelled switches, and it now gives this error:

Parse error: syntax error, unexpected '}' in /home/sassydra/public_html/crazyrealms/lotgd-1.1.0/modules/questing.php on line 94

Thank you sichae for the fast reply... I am learning fast but with coding I would rather KNOW what I am doing before changing it like saucy said... Smiley
Logged
Sichae
iMod God
SVN Users
Mod God
*
Offline Offline

Posts: 3458


If ya didn't get it by now... you're hopeless...


View Profile WWW
« Reply #5 on: January 16, 2007, 07:59:27 AM »

Remove line 92.
Logged

If you didn't understand anything in the above post, don't try to attempt anything suggested.

Maeher
Codemeister
****
Offline Offline

Posts: 362


There's nothing to see here...


View Profile
« Reply #6 on: January 16, 2007, 09:01:12 AM »

Quote
Parse error: syntax error, unexpected '{' in /home/sassydra/public_html/crazyrealms/lotgd-1.1.0/modules/questing.php on line 75

Something completely different, I'm wondering about:

The said file is neither part of the module builder nor would it have been in the right location, if it was.

And taking a look at the posted code confirms that we are talking about a completely different module here.

That means, the error has nothing to do with the module builder and the discussion about it should take place somewhere else, shouldn't it?
Logged

There is no signature...
Elessa
Faerie
Mod God
*****
Offline Offline

Posts: 3598


short, sweet and to the point


View Profile
« Reply #7 on: January 16, 2007, 10:08:09 AM »

Quote
Parse error: syntax error, unexpected '{' in /home/sassydra/public_html/crazyrealms/lotgd-1.1.0/modules/questing.php on line 75

Something completely different, I'm wondering about:

The said file is neither part of the module builder nor would it have been in the right location, if it was.

And taking a look at the posted code confirms that we are talking about a completely different module here.

That means, the error has nothing to do with the module builder and the discussion about it should take place somewhere else, shouldn't it?

yes, it does.  a little investigation has shown this code to be an exercise from a module in the downloads area called "How to:  Writing Your First Module.".

also, rhea, please attach files to the post rather than exploding the thread with the entire code block.  for those of us using small laptops it will be very much appreciated.
Logged

Uuma ma ten rashwe, ta tuluva a lle

Play the latest beta version here on LoGD DragonPrime - Axebridge
SaucyWench
Mod God
*****
Offline Offline

Posts: 2238


I'm a good girl.


View Profile WWW
« Reply #8 on: January 16, 2007, 05:45:11 PM »

Oh dear. A quick look at that file in the downloads area shows it to be staggeringly complex for a "first module" exercise (and I won't go into the cringeworthy spelling and grammar errors).

It's more like "how to make an amazing module that cooks, cleans, paints the house, and babysits the kids while you're out on the town". It may have its merits, but it's not geared towards a beginner in any way shape or form, using a lot of jargon that only an experienced coder would understand. It never claimed to be a beginner's exercise of course, but unfortunately most of the people who are here and need a "first module" tutorial aren't already experts in PHP.
Logged

SaucyWench
Owner of GemDust.com and Darton City proudly hosted by LunarPages
Elessa
Faerie
Mod God
*****
Offline Offline

Posts: 3598


short, sweet and to the point


View Profile
« Reply #9 on: January 16, 2007, 06:04:21 PM »

Oh dear. A quick look at that file in the downloads area shows it to be staggeringly complex for a "first module" exercise (and I won't go into the cringeworthy spelling and grammar errors).

It's more like "how to make an amazing module that cooks, cleans, paints the house, and babysits the kids while you're out on the town". It may have its merits, but it's not geared towards a beginner in any way shape or form, using a lot of jargon that only an experienced coder would understand. It never claimed to be a beginner's exercise of course, but unfortunately most of the people who are here and need a "first module" tutorial aren't already experts in PHP.

which is why the "creating your first module (tutorial)" under the resource pages is a much better place to start.  it gives a step by step overview of basic php coding of a module.

i think the name of the download in the file sharing area is misleading.  it shall be changed.
Logged

Uuma ma ten rashwe, ta tuluva a lle

Play the latest beta version here on LoGD DragonPrime - Axebridge
Middleclaw
Codemeister
****
Offline Offline

Posts: 254


You said what?


View Profile WWW
« Reply #10 on: January 16, 2007, 07:19:29 PM »

I'm quite bemused that this has ended up in the completed modules section as I see no complete modules on this thread. All I see are requests for help.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
36 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search