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
  #16  
Old 12-09-2007, 10:13 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
If we had support for global functions the way I wanted (including Control-NPC in the function lookup), it would be a simple and easy deal to have global functions (temp.var = TObjectType();) to return the new object instance.
__________________
Reply With Quote
  #17  
Old 12-09-2007, 10:32 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Inverness View Post
If...
Anyhow...

I made an addition to my TMap set. For those of you who want to use it, I've made a static function for it:

class_tmap_static (Class)
PHP Code:
public function mergemap1map2mergeRules )
{
  
// Sanity Check
  
if ( !map1.instanceOf( TMap ) || !map2.instanceOf( TMap ))
  {
    echo(
"Input aren't TMaps!");
    return 
null// Force programmer to input CORRECT Data!
  
}

  
// Change Merger to supplied one
  
temp.oldMerger this.mergeValue;
  if ( 
mergeRules != null )
    
this.mergeValue mergeRules;

  
// Copy first Map to a new map
  
temp.sum this.newInstancemap1.toArray() );
  
temp.keys temp.sum.keySet();

  
// Add second map to new map
  
temp.mapSet map2.toArray();
  for ( 
temp.mapValuetemp.mapSet )
  {
    
// If new map contains given key
    
if ( temp.mapValue[0in temp.keys )
    {
      
// Merge them together
      
temp.newValue mergeValue(
        
temp.mapValue[0], // key
          
temp.mapValue[1], // val1
          
temp.sum.gettemp.mapValue[0] ) // val2
        
);
      
      
temp.sum.puttemp.mapValue[0], temp.newValue );
    } else {
      
// Otherwise, put second map data to the new map.
      
temp.sum.puttemp.mapValue[0], temp.mapValue[1] );
    }
  }
  
  
// Revert back to old merger
  
this.mergeValue temp.oldMerger;  

  return 
temp.sum;
}

function 
mergeValuekeyval1val2 )
// Default
  // val1 + val2 should be the same as val2 + val1.
  
return (val1 val2);

Example of Usage:
PHP Code:
function onCreated()
{
  
mod1 TMap.newInstance({{"a",3}, {"b"1}} );
  
mod2 TMap.newInstance({{"a",2}, {"b"1}, {"c"1}} );

  
temp.merger = function( keyval1val2 ) {
    switch ( 
key )
    {
      case 
"a":
        return 
val1 val2;
      default:
        return 
val1 val2;
    }
  };

  
mod3 TMap.mergemod1mod2temp.merger );
  echo( 
mod3.toArray() ); // "a,6","b,2","c,1"

Reply With Quote
  #18  
Old 12-09-2007, 10:37 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Novo View Post
Anyhow...
Too complex for average use.
__________________
Reply With Quote
  #19  
Old 12-09-2007, 10:53 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Inverness View Post
Too complex for average use.
But Powerful for those who know how to use it. Additionally, the merger comes with a default way of merging. It isn't necessary to define your own function, but the power is there if you do!

PHP Code:
function onCreated()
{
  
mod1 TMap.newInstance({{"a",3}, {"b"1}} );
  
mod2 TMap.newInstance({{"a",2}, {"b"1}, {"c"1}} );

  
mod3 TMap.mergemod1mod2 );
  echo( 
mod3.toArray() ); // "a,5","b,2","c,1"

Simple for those who don't need more.
Reply With Quote
  #20  
Old 12-09-2007, 11:31 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Novo View Post
But Powerful for those who know how to use it. Additionally, the merger comes with a default way of merging. It isn't necessary to define your own function, but the power is there if you do!

PHP Code:
function onCreated()
{
  
mod1 TMap.newInstance({{"a",3}, {"b"1}} );
  
mod2 TMap.newInstance({{"a",2}, {"b"1}, {"c"1}} );

  
mod3 TMap.mergemod1mod2 );
  echo( 
mod3.toArray() ); // "a,5","b,2","c,1"

Simple for those who don't need more.
Can you tell me an instance where it would be used in-game?
__________________
Reply With Quote
  #21  
Old 12-09-2007, 11:37 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Sure... Phone-Address look-up. In Era.
PHP Code:
Phones.phoneMap TMap.newInstance();

// In various locations around the world
Phones.phoneMap.put("553-4234"this );


// To phone...
otherPhone Phones.phoneMap.get"553-4234" );
otherPhone.chat "*ring* *ring*"
Merger...
Item System:
PHP Code:
items TMap.newInstance();
items.putitemID, {quantstate});

merger = function( keyval1val2 ){ return {val1[0] + val2[0], val1[1] || val2[1]}; }
items TMap.mergeitemsTMap.newInstance( {{ itemIDquant}}, merger ); 
... There are many situations that it could come up.

What I use it for is to have a cumulative effects from the clothing that the player uses.
For instance, let's say 'Speed'...
PHP Code:
Special Boots TMap.newInstance( {{"Speed"5}});
Other Clothing TMap.n... ...

mods playerMods;
mods TMap.mergemodsracialMods );
for ( 
clothesall worn clothes )
  
mods TMap.mergemodsclothes.mods );

player.speed mods.get("Speed"); 
This is done FOR-ALL possible (and future) attributes:

PHP Code:
  temp.modList temp.mod.toArray();
  for ( 
temp.modtemp.modList )
    
clientr.(@ temp.mod[0] ) = temp.mod[1]; 
Reply With Quote
  #22  
Old 12-10-2007, 12:49 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Novo View Post
Sure... Phone-Address look-up. In Era.
That may 'work' but using a specialized function is much simpler and to the point.
Quote:
Originally Posted by Novo View Post
What I use it for is to have a cumulative effects from the clothing that the player uses.
I just scan equipped items in the mud object and add their affects to the player's.

You're really over-complicating things that are simple to do with regular scripts. Thats not a good way to bring new scripters into the scene.
__________________
Reply With Quote
  #23  
Old 12-10-2007, 01:05 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Inverness View Post
That may 'work' but using a specialized function is much simpler and to the point.
I just scan equipped items in the mud object and add their affects to the player's.

You're really over-complicating things that are simple to do with regular scripts. Thats not a good way to bring new scripters into the scene.
Inverness, I've provided quite a dynamic way to do a variety of things. If you don't appreciate it for whatever reason you have (which seems to be whatever you can seem to think of), then that's that. Otherwise... There are MANY ways to skin a cat. This is one of them...

I don't think introducing new programmers to concepts such as these will help... But alternatively, for those in the know, these techniques could be used with a wide range of successful usage. Ultimately, by my publishing the code, I didn't make it ANY HARDER to learn to script. In fact, that wasn't even my targeted audience. (Additionally, new programmers could learn by example, so they might not see the full utility, but something like that could let them see how reflective programming could be done )

Whether it is overcomplicating something, or providing a bigger re-usability... It doesn't matter that much. Sure, some things just need a little function to work. Others will need more. And in the end, everything can be hard-coded as one massive monolith. In fact, you could program Graal in ONE FUNCTION.

Now, if you want to argue the value of TMap... I just provided it as a quick freebie and numerous incidents it could be used. If you're debating about Class System... I think you would already be in a level where you can use it if you considered that it is beneficial to use it in the first place. I provided quite a bit of flexibility.

Ultimately, I AM SORRY FOR GIVING YOU FREE CODE, go cry me a river. ( I refuse to feed your troll habits any further. )
Reply With Quote
  #24  
Old 12-10-2007, 01:21 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 Novo View Post
I AM SORRY FOR GIVING YOU FREE CODE
You should be!
__________________
Reply With Quote
  #25  
Old 12-10-2007, 02:12 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Novo View Post
<snip>
My issue is because I did exact same thing about a year ago and found that it wasted too much time and CPU making things super flexible and modular rather than just scripting it to do what it needs to do in less time.

Though it seems our situations are different if you don't have something you need to be working on and are just scripting for fun. Though, if you do have something you need to do with this all (like making the system for a server) I wouldn't suggest such things.

I'm just trying to save you from wasting time overdoing it :P, redesigning systems and such can kill a server under construction.
Quote:
Originally Posted by cbkbud View Post
You should be!
Go away, the grown-up scripters are talking now.
__________________

Last edited by Inverness; 12-10-2007 at 02:31 AM..
Reply With Quote
  #26  
Old 12-10-2007, 03:55 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Inverness View Post
Go away, the grown-up scripters are talking now.
But...he...wasn't making any sort of scripting comment. ._.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #27  
Old 12-10-2007, 05:17 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by coreys View Post
But...he...wasn't making any sort of scripting comment. ._.
It wouldn't be far off.
You're supposed to nip it in the bud. *Shining aura of pure awesome*
__________________
Reply With Quote
  #28  
Old 12-10-2007, 05:42 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Quote:
Originally Posted by Inverness View Post
*Shining aura of pure awesome*
I WANT ONE! D:
__________________
Stan.
Reply With Quote
  #29  
Old 12-10-2007, 06:22 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Kyranki View Post
I WANT ONE! D:
You'll never have one.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #30  
Old 12-10-2007, 05:34 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by Inverness View Post
Go away, the grown-up scripters are talking now.
Hi
__________________
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 09:06 AM.


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