Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Referencing Weapons Clientside (https://forums.graalonline.com/forums/showthread.php?t=134269970)

devilsknite1 05-19-2015 08:41 PM

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?

cbk1994 05-19-2015 10:29 PM

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.

scriptless 05-19-2015 10:35 PM

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?

Crow 05-20-2015 07:28 AM

Quote:

Originally Posted by scriptless (Post 1736317)
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.

scriptless 05-20-2015 06:21 PM

Quote:

Originally Posted by Crow (Post 1736323)
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 (Post 1555802)
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

Crow 05-20-2015 06:32 PM

¯\(´-´)/¯


All times are GMT +2. The time now is 04:38 AM.

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