Joel Posted August 4, 2008 Share Posted August 4, 2008 Simple Funtions Hey people I will show you how to create simple functions for Mccodes instead of creating loads off files. So create a file, Name it anything, I will call mine test.php Now we would need this code in side the file: <?php include "globals.php"; /*------------------------ Our functions will go here. ------------------------*/ $h->endpage(); ?> Now we need to create the Cases for the functions, So let me update the code above: <?php include "globals.php"; switch($_GET['action']) { case 'test1': test1(); break; case 'test2': test2(); break; default: index(); break; } $h->endpage(); ?> You can have more Cases if you wish but you will need to create more functions, so now we have the Cases, we can start doing the functions, let me show you an example below off how we will do the functions: <?php include "globals.php"; switch($_GET['action']) { case 'test1': test1(); break; case 'test2': test2(); break; default: index(); break; } function index() { global $ir,$c,$userid,$h; print "what ever you want here"; } $h->endpage(); ?> The index will be the main page of the file. Let me show you how it works: <?php include "globals.php"; switch($_GET['action']) { case 'test1': test1(); break; case 'test2': test2(); break; default: index(); break; } function index() { global $ir,$c,$userid,$h; print "what ever you want here"; } function test1() { global $ir,$c,$userid,$h; print "test1 success"; } function test2() { global $ir,$c,$userid,$h; print "test2 success"; } $h->endpage(); ?> Now if you have both test1 and test2 functions in there, then go to your address bar and test them, so the URL would be like this: http://www.YOURGAME.com/FILENAME.php?action=test1 and http://www.YOURGAME.com/FILENAME.php?action=test2 And then it should say Success! Now that was simple wasn't it? Any help just say, I am happy to help! Quote Link to comment Share on other sites More sharing options...
KingRise Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Funtions nice, we need people like you to help out the noobs that haven't got a clue lol....thanks for posting mate Quote Link to comment Share on other sites More sharing options...
Joel Posted August 4, 2008 Author Share Posted August 4, 2008 Re: Simple Funtions nice, we need people like you to help out the noobs that haven't got a clue lol....thanks for posting mate Thanks for your comment, and functions are easy to use if you no what to do, so yeah it will help out the "noobs" lol. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Funtions * Topic Moved * This thread doesn't supply an explanation of usage of any sort, and it is linked to DBS code - not useful for everyone, try writing about something that doesn't require any third-party framework/application/script/engine. Quote Link to comment Share on other sites More sharing options...
Joel Posted August 4, 2008 Author Share Posted August 4, 2008 Re: Simple Funtions * Topic Moved * This thread doesn't supply an explanation of usage of any sort, and it is linked to DBS code - not useful for everyone, try writing about something that doesn't require any third-party framework/application/script/engine. Oh alright sorry. Quote Link to comment Share on other sites More sharing options...
Tonka Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Funtions if you want this to work with v2's $db-> properly you need to replace global $ir,$c,$userid,$h; with global $db,$ir,$c,$userid,$h; notice the $db added to the second one Quote Link to comment Share on other sites More sharing options...
POG1 Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Funtions <html> <head><title>Example</title> <body bgcolor="#cccccc"> <h3>Example Page</h3> <?php if(isset($_GET['action']) { switch($_GET['action']) { case 'a': include('inc/a.inc.php'); break; case 'b': include(inc/b.inc.php'); break; } } else { index? } ?> </body> </html> instead of having loads of lines of code you could have them included... just a different way of doing it :P Quote Link to comment Share on other sites More sharing options...
KingRise Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Funtions :S Quote Link to comment Share on other sites More sharing options...
Floydian Posted August 5, 2008 Share Posted August 5, 2008 Re: Simple Funtions pog-one, that's a good point, however, it's not necessary most of the time. Most scripts I make for my game or other people's games, have like four or five cases. Splitting one file, such as attack.php over five seperate files is just ridiculous IMHO. At least, splitting it up in some sort of haphazzard way as doing one function in each file is overkill. Files should be split according to the logic flow. For instance, mccodes has a glob_func.php file with many functions in it common to many files. globals.php is good since a header and footer is needed on every page. But, take attack.php. Do you really need an attacklost.php? and an attackwon.php? For god sakes! pog-one, I'm definitely in agreement with you that splitting up files like you're talking about is very useful in the right situation. A perfect place for this is the admin panel. You could have all user related functions in one file, log functions in another, and so on. Any staff functions that only need one function could be in the main staff file or in a staff/misc.php file. Quote Link to comment Share on other sites More sharing options...
POG1 Posted August 5, 2008 Share Posted August 5, 2008 Re: Simple Funtions yeah good point. I havent used mccodes in a while but for my game in the admin pannel i have done a switch include, just makes the coding cleaner. functions.php <?php // The switch functions could be put into a single "switchFunction.php" for all pages // ...all the functions function mailbox() { globals $blah; print 'works!'; } // more functions ?> and if you wanted to code a page all the coding needed would be so much less. <html> <head><title>Example</title> <body bgcolor="#cccccc"> <h3>Example Page</h3> <div style="width:60%; border:1px solid #666666"> <?php switch($_GET['action']) { case '1': index(); break; case '2': mailbox(); break; default: index(); break; } } ?> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
KingRise Posted August 5, 2008 Share Posted August 5, 2008 Re: Simple Funtions yeah Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.