Larian Banner: Baldur's Gate Patch 9
Previous Thread
Next Thread
Print Thread
#631285 15/10/17 09:33 PM
Joined: Sep 2017
G
stranger
OP Offline
stranger
G
Joined: Sep 2017
Hi,

I'm looking through the provided Osiris script "_Greevers_Little_Helpers" at the moment, and am wondering about how procs are executed by Osiris.

If you take a mainstream programming language that features function overloading then the function that is executed is usually choosen by the type of the argument.

Now looking at this snippet from Osiris:

Code
PROC
Proc_CountHelper((STRING)_ID)
AND
NOT DB_CountHelper(_ID,_)
THEN
DB_CountHelper(_ID,0);

PROC
Proc_CountHelper((STRING)_ID)
AND
DB_CountHelper(_ID,_OldValue)
AND
IntegerSum(_OldValue,1,_Value)
THEN
NOT DB_CountHelper(_ID,_OldValue);
DB_CountHelper(_ID,_Value);


Both procs are named exactly the same and both take only a single parameter which has the same type and name. The first creates the database if it not exists, the second increments the counter.

In the mainstream languages that I know this would not work as it's not clear how to pick which proc to execute. Which is why I wonder which of the two procs get's executed. I'm assuming both execute and the conditions are the only thing deciding which is executed fully until the end?


Joined: Apr 2013
N
addict
Offline
addict
N
Joined: Apr 2013
Exactly. If two procs have the same name and arity, they are both evaluated and executed in the order they were declared.

Joined: Sep 2017
G
stranger
OP Offline
stranger
G
Joined: Sep 2017
Originally Posted by Norbyte
Exactly. If two procs have the same name and arity, they are both evaluated and executed in the order they were declared.


Thanks, you also directly answered my second question which I planned to ask since I'm not at a computer with the editor at the moment (the order of execution). smile

I guess the same is also true for queries, and that's the reason queries can be used for OR conditons (as mentioned in the wiki)?

Joined: Jun 2015
F
enthusiast
Offline
enthusiast
F
Joined: Jun 2015
What makes it more difficult is that PROCs of the same name can be defined in different files and if order of execution matters the lexical order of the file names where the PROCs were defined comes into play.

The same is true for QRYs and events (including those that start with an IF).

Osiris also does not have real variables, so the above code is totally different from what you've used so far. In a 'normal' programming language (like PHP) the above code could be written like ...

Code
  function Proc_CountHelper( string $id )
  {
    global $DB_CountHelper;
    // equivalent of the first PROC
    if ( ! isset( $DB_CountHelper[$id] ) )
    {
       $DB_CountHelper[$id] = 0;
    }
    // equivalent of the second proc
    $DB_CountHelper[$id]++;
  }


Osiris does know some kind of 'overloading' though because another PROC might have the same name but if it has a different signature (number of parameters) it's considered a different PROC.
(That's how they implemented some kind of 'default parameter' for API calls in Original Sin 1.)

I'm not quite sure if only different parameter types make a different PROC, I think that would cause a compile error. ('Databases' cannot have same amount and different types, and 'databases' and PROCs have many similarities, so I assume it would be an error.)
But to be more sure you could return to Jack and his Apples in Larian's scripting tutorial videos for Original Sin 1 on YouTube ;-)



Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.5