Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   overloading function params? (https://forums.graalonline.com/forums/showthread.php?t=63432)

jake13jake 01-14-2006 02:36 PM

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.

ApothiX 01-14-2006 06:24 PM

What is the player's chat being set to when the line:
player.chat = params.size();
is executed?

Admins 01-14-2006 06:58 PM

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).

jake13jake 01-14-2006 07:30 PM

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.


All times are GMT +2. The time now is 08:24 AM.

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