Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-24-2011, 04:13 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
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:
public function Purchase(ab
Would that seem like something a public function is? And will work?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 02-24-2011, 04:21 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Let's say you have a level NPC with this code:
PHP Code:
function hit() {
  
this.chat "I was hit!";

If you tried to call this function from another script, you wouldn't be able to.

PHP Code:
myNPC.hit(); 
You would see a "function not accessible" error.

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:
// weapon Health
//#CLIENTSIDE
public function heal() {
  
player.hearts player.fullhearts;

then, in any other clientside script, you could do

PHP Code:
Health.heal(); 
in order to call the 'heal' function in the Health weapon.

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.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.