Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and are struggling to install it? Cronwerks now installs mods for only $3/$2.50 here.


AuthorTopic: Easier way to write addons  (Read 62 times)

Spudinski

  • Global Moderator
  • Basic Member
  • *****
  • Reputation Power: 41
  • Spudinski has no influence.
  • Offline Offline
  • Posts: 51
  • I have cookies!
    • View Profile
    • WWW
    • Email
Easier way to write addons
« on: February 07, 2010, 04:49:53 PM »
Well, it's something that have come to my attention - the way developers write the scripts.

I think there should be a standard template on which to begin to write an addon or rewrite a script.
First off all, I think moving the includes, mysql queries, and all that stuff, to a separate file, or try to not use it at all.

Here is an example of what I think could be done;
Code: [Select]
<?php

/**
   * Instead of having this whole messy starting point
   */

session_start();
require 
"global_func.php";
if(
$_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require 
"header.php";
$h = new headers;
$h->startheaders();
include 
"mysql.php";
global 
$c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm);
$h->menuarea();

{ ... 
actual script ... }

$h->endpage();
?>

Code: [Select]
<?php

/**
   * Rather have something like this
   */

$mccodes->initialize(); // this is more descriptive  than $h->blah()...

{ ... actual script ... }

$mccodes->end(); 

?>

In doing that, it would make documenting and learning how to program with the engine much easier.
I'm not implying that we should go about changing every aspect, but at least some of it.

I think that being able to document certain things will give new game owners the ability to start learning to program for the engine much faster, and they will gain better knowledge than just the simple scripts some people put out there - in addition, if we can document the functions properly, we can release tutorials for creating addons etc., but I personally don't expect to know each function on the current lite model, simply because the names doesn't make sense at all.


I really don't know what you other guys/gals think about this approach, so please give me your input.
I accept all critics, good or bad.

Logged
If you see a post that just doesn't just seem right, send me a PM.
Offering services for small-type games and websites, send me a PM if you want/need something done.