Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-19-2015, 08:41 PM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Referencing Weapons Clientside

So I know from experience that referencing weapons clientside can be done in multiple ways, the easiest two probably being the following.

Method 1:
Weapon NPC Foo
PHP Code:
//#CLIENTSIDE
function onCreated() {
  ( @ 
"Bar" ).foobar();

Weapon NPC Bar
PHP Code:
//#CLIENTSIDE
public function foobar() {
  
// code

Method 2:
Weapon NPC Foo
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
findWeapon"Bar" ).foobar();

Weapon NPC Bar
PHP Code:
//#CLIENTSIDE
public function foobar() {
  
// code

Which way is the "correct" way of referencing another object clientside? What are the differences between the two, if any? In the past I have always used method 1, but now I find myself most certainly wanting to use method 2 as it is an actual command loading an object (findweapon/findweaponnpc) rather than simply listing another weapon name. Might there be more functionality advantages to method 2 versus method 1 or vice versa that I might be missing?

Last edited by devilsknite1; 05-19-2015 at 11:20 PM..
Reply With Quote
  #2  
Old 05-19-2015, 10:29 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
You can omit the parentheses if the name doesn't contain any special characters:

PHP Code:
Bar.foobar(); 
The @ is also always unnecessary, it's a bad habit that I'm afraid I helped popularize:

PHP Code:
("-Something/With/Weird/Characters!").foobar(); // works fine 
Personally, I don't see any reason to use the findWeapon syntax. Usually for weapons that I want other scripts to call, I wouldn't worry too much about the name (e.g. -HealthSystem), and instead do something like:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
Health this;

...with the idea of it being better to be explicit rather than implicit (other scripts can now do Health.foobar()).

The (minimal) added benefit is that you can avoid using parentheses (no dashes), you're reminded that other scripts might be calling it, and you avoid trouble with renames.

There might be some benefit to the findWeapon syntax in that you can avoid conflicts between other objects, but I've never really seen that happen in all the time I was coding.
__________________
Reply With Quote
  #3  
Old 05-19-2015, 10:35 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Chris beat me to it. I spent to much time looking for the tips and trick's thread dusty started. I think who was it crow? that mentioned that?
Reply With Quote
  #4  
Old 05-20-2015, 07:28 AM
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
Quote:
Originally Posted by scriptless View Post
Chris beat me to it. I spent to much time looking for the tips and trick's thread dusty started. I think who was it crow? that mentioned that?
Mentioned what? The whole something = this thingy? I may have suggested that somewhere, sure. Definitely not initially my idea.
__________________
Reply With Quote
  #5  
Old 05-20-2015, 06:21 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by Crow View Post
Mentioned what? The whole something = this thingy? I may have suggested that somewhere, sure. Definitely not initially my idea.
Yeah this.. Didn't mean to say was your idea just meant you mentioned it in a pretty popular thread

Quote:
Originally Posted by Crow View Post
Another handy thing is assigning WNPCs to vars. Let's say you got the following in -System/Inventory:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
inventory this;
  
// more stuff..
}

public function 
Toggle() {
  
// toggle

Then you could do something like this in -System/InputHandler:
PHP Code:
//#CLIENTSIDE
function HandleKey(key) {  // careful, I made this one up, assuming it was implemented in the WNPC earlier
  
if (key == "q")
    
inventory.Toggle();
  
// probably more stuff..

http://forums.graalonline.com/forums...ht=tips+tricks
Reply With Quote
  #6  
Old 05-20-2015, 06:32 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
¯\(´-´)/¯
__________________
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 04:43 PM.


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