View Single Post
  #7  
Old 09-18-2011, 06:46 PM
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
Quote:
Originally Posted by oralgnome View Post
well, player.dir is generally clientside* so you can't really use it in a class/serverside in general until you pass it serverside
No it's not, player.dir can be accessed serverside.

Quote:
relatively, you can pass a var in a weapon from the clientside to the serverside like this:

(With trigger.server), but how would you pass that temp.dir var to the class then?
I think you misunderstand how classes work. All a class does is extend a weapon or NPC. It doesn't stand on its own.

Class functions_bank
PHP Code:
function deposit(temp.amountToDeposit) {
  
// obviously this is just an example, don't actually use this
  
player.rupees -= temp.amountToDeposit;
  
player.bank += temp.amountToDeposit;

Weapon ATM
PHP Code:
function onCreated() {
  
this.join("functions_bank");
}

function 
onActionServerSide(temp.cmdtemp.amount) {
  if (
temp.cmd == "deposit") {
    
this.deposit(temp.amount);
  }
}

//#CLIENTSIDE
function ChatBar.onAction() {
  if (
ChatBar.text.starts("/deposit")) {
    
triggerServer("gui"this.name"deposit"player.chat.substring(9).trim());
  }

The example above shows a very simple use of classes.

When you use join(classname) on a weapon or an NPC, imagine the script of the class being copied and pasted into the weapon. You can't pass things to a class; classes extend an object. They aren't their own objects.

Quote:
in java you'd just redefine the var with the classname like

PHP Code:
// not gs2
     
classname.firstnum secondclass.num
and then you'd just initiate the num var in secondclass for use

how would you accomplish this in gs2?
Classes in Java are completely different than GScript ones. The only real similarity is that they have the same name. You can join an infinite number of classes in GScript to a single weapon or NPC.

If you need to pass data between two objects, such as two different weapons, you can do that in a few ways:

In script of -WeaponOne:
PHP Code:
temp.otherWeapon = (@ "-WeaponTwo");

// calls and triggers
temp.otherWeapon.hello("hi!"); // requires -WeaponTwo to have a "public function hello(temp.data) {" in it
temp.otherWeapon.trigger("hello""hi"); // calls "onHello(temp.data)" in -WeaponTwo.

// you can also set data directly
temp.otherWeapon.hello "hi"
__________________
Reply With Quote