 |
 |
 |
 |
| Author |
Message |
ncrsn
Joined: 10 Feb 2006 Posts: 107
|
Posted: Mon Mar 03, 2008 10:54 am Post subject: MethodScript |
|
|
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 , it might act like it's . 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. |
|
 |
|
|
 |
 |
|
|