Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-18-2011, 06:36 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
isn't it player.dir == not = ?

anyway i'm interested in this as well because i've no idea how you can pass a dir to a class like that
Yes, it should have been ==.

What do you mean by passing it to a class?
__________________
Reply With Quote
  #2  
Old 09-18-2011, 06:39 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
Yes, it should have been ==.

What do you mean by passing it to a class?
well, player.dir is generally clientside* so you can't really use it in a class/serverside in general until you pass it serverside

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

PHP Code:
function onActionServerside(cmddir){
if (
cmd == "bomb"){
        
temp.npc putnpc2(player.xplayer.y"bomb");
        
temp.npc.join("personal_pig132_bomb");
        
sendtonc(temp.dir);
  }
}

//#CLIENTSIDE

function onWeaponFired(){
    
temp.dir player.dir;
    
triggerserver("gui"this.name"bomb"temp.dir);

(With trigger.server), but how would you pass that temp.dir var to the class then?

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?
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?
Reply With Quote
  #3  
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
  #4  
Old 09-18-2011, 07:02 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
post
still, good to know that you can pass vars from weapon to weapon but not from weapon to class (since gs2 classes apparently extend instead of inherit)

but yeah, by 'passing vars' i literally meant re-defining one already defined

anyway, OT: yes player.dir is serverside but it can't be read from/to a class (point proven i'm guessing)
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?

Last edited by oralgnome; 09-18-2011 at 07:21 PM..
Reply With Quote
  #5  
Old 09-18-2011, 07:14 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
It seems you don't understand what a class really is.
Reply With Quote
  #6  
Old 09-18-2011, 07:17 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by Crow View Post
It seems you don't understand what a class really is.
- snip -

point proven I guess. you pretty much can't use player.dir like he was using because it won't register properly/inherit from the weapon. back 2 the drawing board

still don't really understand what tig was talking about though (because I assume he was using a class to place the bomb/npc)
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?

Last edited by oralgnome; 09-18-2011 at 07:28 PM..
Reply With Quote
  #7  
Old 09-18-2011, 07:23 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
still, good to know that you can pass vars from weapon to weapon but not froanyway, OT: yes player.dir is serverside but it can't be read from/to a class (point proven i'm guessing)
Yes it can .

Again, classes just extend an existing object. If you can access the player object, then you can access the player's dir.
__________________
Reply With Quote
  #8  
Old 09-18-2011, 07:27 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
Yes it can .

Again, classes just extend an existing object. If you can access the player object, then you can access the player's dir.
no idea why it's not working for me though

edit: my class was serverside whoops (//#CLIENTSIDE allows access to the player. object whereas previously it did not? anyway cool I guess it can be used serverside but first has to be read and not inherited first)
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?

Last edited by oralgnome; 09-18-2011 at 07:39 PM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:35 PM.


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