PenUltima Online

It is currently Wed Aug 20, 2008 2:10 pm

All times are UTC - 4 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: MethodScript
PostPosted: Mon Mar 03, 2008 10:54 am 
Offline
User avatar

Joined: Fri Feb 10, 2006 4:15 am
Posts: 202
Processing item's methodscript should not cease if another method of its is called meantime. Code:

Some item's methodscript
Code:
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:
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:
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:
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:
item.Method()
, it might act like it's
Code:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 11:15 pm 
Offline
User avatar

Joined: Fri Feb 10, 2006 4:15 am
Posts: 202
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:
Item    0x5510
{
    Name    ExampleItem
    ----
    MethodScript   method/exampleitem
}


package/method/exampleitem.src
Code:
program Install( item )
    // Would print 0x5510 on POL start
    print(item);
endprogram


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 4 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl