Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-07-2011, 02:05 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
findNearestPlayers(x, y)

Serverside, in a DB NPC,

PHP Code:
this.level.findNearestPlayers(3232);
this.findNearestPlayers(3232);
findNearestPlayers(3232); 
Only the last one works. What object is findNearestPlayers a method of?
__________________
Reply With Quote
  #2  
Old 03-07-2011, 02:15 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
It could just be a global function.
Reply With Quote
  #3  
Old 03-07-2011, 02:33 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
Quote:
Originally Posted by WhiteDragon View Post
It could just be a global function.
If so, it should be moved to TServerLevel so that it can be used in conjunction with findLevel.
__________________
Reply With Quote
  #4  
Old 03-07-2011, 02:53 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
It'd be cool if we could do something like..

PHP Code:
function onCreated() {
  
TServerPlayer.test = function () {
    echo(
this.account);
  };
  for (
aallplayersa.test(); // Result: RC Spammed with Accounts

I guess the above doesn't really apply here but being able to extend functionality of a built-in Graal class/object without joining a class would be cool.
__________________
Quote:
Reply With Quote
  #5  
Old 03-07-2011, 02:59 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
Quote:
Originally Posted by fowlplay4 View Post
It'd be cool if we could do something like..

PHP Code:
function onCreated() {
  
TServerPlayer.test = function () {
    echo(
this.account);
  };
  for (
aallplayersa.test(); // Result: RC Spammed with Accounts

I guess the above doesn't really apply here but being able to extend functionality of a built-in Graal class/object without joining a class would be cool.
Adding methods to default objects would indeed be great. In JavaScript, you can edit object "prototypes":

PHP Code:
// from http://www.flzone.com/go?7678
String.prototype.replace = function(patternreplacement) {
  return 
this.split(pattern).join(replacement);

Another idea which I think would work better for GScript would be if you could create a class with the name "TServerPlayer" and all TServerPlayer objects would inherit those methods. This can already be done by joining classes to the player, but for stuff like TServerLevel and TGraalVar (for strings) it would be invaluable. I would love to be able to add string.replace(a, b).
__________________
Reply With Quote
  #6  
Old 03-07-2011, 04:00 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
findnearestplayers() is operating on players[] instead of level.players, that's why it cannot simply made to be a level function. The players[] array is only containing players from the nearby 3x3 levels, while level.players[] can contain thousands of players.
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 08:35 AM.


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