MethodScript

Archive of the older Feature Request Forum Posts
Locked
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

MethodScript

Post by ncrsn »

Processing item's methodscript should not cease if another method of its is called meantime. Code:

Some item's methodscript

Code: Select all

use os;

program install( )
    return 1;
endprogram

exported function getcustomvalue( item, value )
    // Needed later.
    // GetProp() method is alias of GetObjProperty(item, value);
    return item.GetProp(value);
endfunction

exported function startexternalscript( item )
    // This will never actually return anything, see below.
    return Run_Script_To_Completion("externalscript", item);
endfunction
External script lauched in methodscript

Code: Select all

program externalscript( item )
    // If this script is launched in item's methodscript, calling item's method will abort the older one.
    item.getcustomvalue("Important");
    
    // Thus it will never return a thing.
    return 1;
endprogram
Snippet for testing purposes.

Code: Select all

program textcmd_externalscriptmethod( who )
    var item := Target(who);
    // Useless.
    print(item.externalscript());
endprogram
The way I see it, correct way to overcome this is
a) not to launch any critical process that uses same item's method via its methodscript
b) should item's method be needed in another method, it should be called function-like:

Example of using methods; modified startexternalscript().

Code: Select all

external function startexternalscript( item, value )
    var params := { item };
    // Wrong way: this will cease the process.
    // params += item.GetCustomValue(value);
    // Right way: using like function.
    params += GetCustomValue(item, value);
    
    return Run_Script_To_Completion("externalscript", params);
    
endfunction
So far so good; problem can be solved? Not-so.

Should I want to use any item's method in externalscript, it won't work. Using method like function is fine as long as the program (src-file) is methodscript; outside it, I'd have to include the very same function and it would work like a function, which does not provide benefits of having methodscripts. Debugging becomes hard when you have scripts where sometimes methods are used like Function(item), and sometimes (correctly) as item.Method().

This is because the one major benefit that methodscript has: there is only one process per itemdesc element that has methodscript declared (likewise packethooks).

So the suggestion.

If item.Method() is used in process that IS the methodscript (remember, there is only one per itemdesc element), it would be either compiled or converted runtime to work like a it's a function: thus, if I use

Code: Select all

item.Method()
, it might act like it's

Code: Select all

Method(item)
. No problems what-so-ever, because this function does exist in the methodscript!

If core would do that, scripters would not have to keep up whether or not they are using function or another critical script from methodscript, but could solely use the item.Method()-style - the way POL internally handles it would not be important, like it is now.
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

Post by ncrsn »

Another suggestions concerning (item) method scripts. Thought I could as well add it into an existing thread.


If two or more item's that 'share' the same method script (two itemdesc elements that have same MethodScript line, that is), scripter does not know which item type is the one he/she is dealing with *until* one of method script's methods is used!

Should this information be somehow available, one could in example cache every important detail concerning that item (objtype). Maybe add a global variable that would hold a reference to itemdesc element which every item that *uses* the process has in common.

Thus, the feature I'd like to see: item's type (objtype) would be passed as parameter in method script's program().

Result might look like this:

package/config/itemdesc.cfg

Code: Select all

Item    0x5510
{
    Name    ExampleItem
    ----
    MethodScript   method/exampleitem
}
package/method/exampleitem.src

Code: Select all

program Install( item )
    // Would print 0x5510 on POL start
    print(item);
endprogram
Locked