| Blockland Forums > Modification Help |
| Break; And Return; |
| << < (2/3) > >> |
| jes00:
--- Quote from: Ipquarx on January 12, 2012, 10:37:26 AM ---Return is used to end a function and give out a result. Here is an example: --- Code: ---function returnHello() { return "Hello!"; } --- End code --- Now, if you just do returnHello() in the console, it will do nothing. But, if you do echo(returnHello()) in the console, it will say "Hello!", because the returned value is sent to the first variable in the function Echo. Note that functions do not need to have a return, but it's generally a good idea to return errors if there was one. --- End quote --- So if I did --- Code: ---function Blah(%client) { if(%client.fudge == returnTest()) { //Nothing. } } function returnTest() { return 7; } --- End code --- Then it would be the same as doing --- Code: ---function Blah(%client) { if(%client.fudge == 7) { //Nothing. } } --- End code --- If so return is in my opinion pretty useless. |
| CityRPG:
You're not getting it. This is a code snippet from CityRPG: --- Code: ---// Fetches a player's profile (creating it if nessicary). // @ProfileSO function GameConnection::getProfile(%client) { if(!Profiler.isProfileActive(%client.bl_id)) if(Profiler.isProfile(%client.bl_id)) if(Profiler.loadProfile(%client.bl_id)) return Profiler.getProfile(%client.bl_id); else return -2; else if(Profiler.createProfile(%client.bl_id)) if(Profiler.loadProfile(%client.bl_id)) return Profiler.getProfile(%client.bl_id); else return -2; else return -1; else return Profiler.getProfile(%client.bl_id); } --- End code --- In my code, this function is called over 100 times throughout almost 30,000 lines of code. Imagine having to replace every single instance of %client.getProfile() with that monster I quoted. Also notice how each if() has only a function called in it. These are all returning true/false based on success. Is it active? Existing? Can we load it? Can we create it? Each function also has more is() and get() checks inside of it. There's literally hundreds of contingent returns in play here. |
| Brian Smithers:
For every cell in your body, there are 20 returns in CityRPG. |
| Ipquarx:
--- Quote from: Brian Smithers on January 12, 2012, 03:27:10 PM ---For every cell in your body, there are 20 returns in CityRPG. --- End quote --- more like 50. No im joking, more like .5 really. Do you know how many cells are in the human HAND alone? |
| Brian Smithers:
--- Quote from: Ipquarx on January 12, 2012, 05:12:01 PM ---more like 50. No im joking, more like .5 really. Do you know how many cells are in the human HAND alone? --- End quote --- Yeah. Not enough to fulfill all the returns used in CityRPG. NEVER ENOUGH |
| Navigation |
| Message Index |
| Next page |
| Previous page |