![]() |
public function?
Iv'e seen a lot of "public functions" I think that these functions are accessible in all scripts, am I correct? Saying this...
PHP Code:
|
Let's say you have a level NPC with this code:
PHP Code:
PHP Code:
When you make it public, it can be called by another script. To make something public, all you need to do is change "function" to "public function". For example, if you have a system named Health, and you wanted to add a function for healing a player, your code might look like this: PHP Code:
PHP Code:
In object-oriented programming, it's good style to make all of your internal functions private. The idea is to provide easy functions like "player.heal()" or "player.hurt()". Then, if you ever change how your HP system works, you don't have to change any scripts that use those public functions. You want to hide the nitty-gritty stuff and just provide functions for doing certain tasks. |
| All times are GMT +2. The time now is 12:38 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.