Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-14-2006, 02:36 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
overloading function params?

I remember a while ago I was told that something such as the following would possess the same qualities as overloading functions (and I'm pretty sure it was from Stefan). However, now that I've found a place where I want to use it, I find that params aren't even loading into the function.
PHP Code:
function myFunction() {
  switch (
params.size()) {
  case 
1:
  case 
2:
  case 
3:
  default:
  }

Here is the script that I am working with.
PHP Code:
function dropitem() {
  
player.chat params.size();
  switch (
params.size()) {
  case 
1:
     
temp.dropitem params[0];
     break;
  case 
2:
    
temp.tpercents params[1];
    for (
i=0;i<temp.tpercents.size();i++)
      
tpercents[i] += tpercents[i-1];
    
temp.choice random(0,100);
    for (
i=0;i<temp.tpercents.size();i++) {
      if (
temp.choice <= temp.tpercents[i]) {
        
temp.dropitem params[0][i];
        break;
      }
    }
    break;
  }
  if (
temp.dropitem) {
    
putnpc2(x-1,y-1,"join dropitem_"@temp.dropitem@";");
  }

I would have revived the thread that this was said in, but I can't find it. Unfortunately, I guess I'll have to go about other methods. If I'm just screwing things up, please help me. If not, move this to the future improvements forum or something.
Reply With Quote
  #2  
Old 01-14-2006, 06:24 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
What is the player's chat being set to when the line:
player.chat = params.size();
is executed?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #3  
Old 01-14-2006, 06:58 PM
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
There might be some misunderstanding about "params[]". It is always containing the parameters given to the script call, which means an event occured and is executing either the whole script (old script style) or a single event handler function, or you call a function of another object. When a gani script is executed then params[] will contain the gani parameters passed to setani() or setcharani().

So params[] is not containing the function parameters, that is only the case if you access it in the event handler function. Question is if it should be changed, it could make things more slow. Best solution in your case would be to accept two parameters - if the caller is only providing one parameter then the second parameter will be zero, which you could check. Or you do two different functions, for better readibility and so making it easier for other scripters to understand your code.

Hmmm on the new Graal Bible (http://wiki.graal.net) we should eventually add a script FAQ were such things are added (once they get answered in this forum).
Reply With Quote
  #4  
Old 01-14-2006, 07:30 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Stefan
There might be some misunderstanding about "params[]". It is always containing the parameters given to the script call, which means an event occured and is executing either the whole script (old script style) or a single event handler function, or you call a function of another object. When a gani script is executed then params[] will contain the gani parameters passed to setani() or setcharani().

So params[] is not containing the function parameters, that is only the case if you access it in the event handler function. Question is if it should be changed, it could make things more slow. Best solution in your case would be to accept two parameters - if the caller is only providing one parameter then the second parameter will be zero, which you could check. Or you do two different functions, for better readibility and so making it easier for other scripters to understand your code.

Hmmm on the new Graal Bible (http://wiki.graal.net) we should eventually add a script FAQ were such things are added (once they get answered in this forum).
okay, thanks.
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 01:36 AM.


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